sed to explode a full path

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DannyMc
    New Member
    • Aug 2007
    • 20

    sed to explode a full path

    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
    Recognized Expert Contributor
    • Aug 2007
    • 542

    #2
    Originally posted by DannyMc
    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

    Comment

    • sumittyagi
      Recognized Expert New Member
      • Mar 2007
      • 202

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

      Code:
      basename /home/root/usr2/testdir1
      testdir1
      
      dirname /home/root/usr2/testdir1
      /home/root/usr2

      Comment

      Working...