Computing.Net > Forums > Unix > Sed split directory

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Sed split directory

Reply to Message Icon

Name: weronpc
Date: February 25, 2008 at 14:54:07 Pacific
OS: unix
CPU/Ram: 512
Product: na
Comment:

lets say pwd is "/u/mchi/test"
How do I use sed to get the value test?
Here is what I tried and none returned test.
1)
pwd | sed 's/*[a-zA-Z]\///g'
/u/mchi/test
2)
pwd | sed 's/[a-zA-Z]\///g'
/test

Thanks,
Mike



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: February 25, 2008 at 19:37:49 Pacific
Reply:

Do you know that the unix basename command returns what you are asking for:

basename $(pwd)

Also, the ksh/bash pattern matching operators can perform the same task:

var=$(pwd)
echo ${var##*/}

However, if you insist on a sed solution:

pwd|sed 's,^.*[/\\\\],,g'


0

Response Number 2
Name: weronpc
Date: February 26, 2008 at 11:34:43 Pacific
Reply:

Thanks Nails, basename $(pwd) is what I was looking for.

Cheers,
Mike


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Sed split directory

abt sed www.computing.net/answers/unix/abt-sed/6120.html

sed problem www.computing.net/answers/unix/sed-problem/6964.html

such .sed file? www.computing.net/answers/unix/such-sed-file/4417.html