Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command SED Help 4

Status
Not open for further replies.

AIXtexas

Technical User
Feb 5, 2002
80
US
Does anyone know an easy way to remove the preceeding (/) and the trailing (/.../*) from the below file?

/usr2/.../*
/usr2a/.../*
/usr3/.../*
/usr3a/.../*
/usr3b/.../*
/usr4/.../*
/usr4a/.../*


I only need the usrXX part of this file. It seems there should be a way to do it with SED, but I just cant figure it out. I'm writing a script where I'll need to strip the usrXX part out of this file and compare it with the df output.

Thanks,

Shane
 
sed 's!^/!!;s!/.*!!' /path/to/input

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Code:
echo '/usr2/foo/bar' | sed 's#^/[^/][^/]*/\(.*\)#\1#'

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Thanks everyone, that did the trick!

Shane
 
actually....
Code:
echo '/usr2/foo/bar' | sed 's#^/[^/][^/]*/##'

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Another way:
awk -F/ '{print$2}' /path/to/input

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
cut -d / -f 2 /path/to/file

should also do it (provided there's no double slashes anywhere in the file)...


HTH,

p5wizard
 
Thanks everyone!

Its amazing that there's so many ways to accomplish the same thing.

Shane
 
while read item
do
expr "$item" : "/\([^/]*\)/.*"
done < /path/to/input

# Far from ideal, but a useful model for certain situations

Cheers,
ND [smile]

bigoldbulldog@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top