Connecting Tech Pros Worldwide Help | Site Map

sed to explode a full path

Newbie
 
Join Date: Aug 2007
Posts: 20
#1: Sep 6 '09
Hi,

i am quite new to sed and i wonder if there is anyway for me to explode the full path and take the last variable as the string ???

/home/root/usr2/testdir1 --> so i can take testdir1
/home/root/usr2/testdir3

i need to write a script to tar and gzip a list of directory. please help, i am just lacking of sed part.

thanks!
ashitpro's Avatar
Expert
 
Join Date: Aug 2007
Posts: 389
#2: Sep 7 '09

re: sed to explode a full path


Quote:

Originally Posted by DannyMc View Post

Hi,

i am quite new to sed and i wonder if there is anyway for me to explode the full path and take the last variable as the string ???

/home/root/usr2/testdir1 --> so i can take testdir1
/home/root/usr2/testdir3

i need to write a script to tar and gzip a list of directory. please help, i am just lacking of sed part.

thanks!

I tried this:

echo /home/root/usr2/testdir1 | sed 's:.*/::'

Regards,
Ash
sumittyagi's Avatar
Expert
 
Join Date: Mar 2007
Location: New Delhi, India
Posts: 198
#3: Sep 20 '09

re: sed to explode a full path


why don't you just use basename and dirname commands.

Expand|Select|Wrap|Line Numbers
  1. basename /home/root/usr2/testdir1
  2. testdir1
  3.  
  4. dirname /home/root/usr2/testdir1
  5. /home/root/usr2
Reply


Similar Unix / Linux / BSD bytes