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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

matching nth string 2

Status
Not open for further replies.

cptk

Technical User
Mar 18, 2003
305
US
I have ...

x=`tar -tvf file.tar | awk 'print $8}'`

which returns a full dir string with file name ...

x="dir/dir/filename dir/dir/filename2 dir/dir/dir/dir/filename3 ... etc."

I want to remove the filename portion of each element in the variable $x (without going through a some sort of loop) as an additional pipe ...
e.g. -
x=`tar -tvf file.tar | awk 'print $8}' | awk ???`

with desired result:
x= "dir/dir/ dir/dir/ dir/dir/dir/dir/"

I tried using functions: index, match, etc. but I can't seem to pull-out the file portion.

I'm open to unix ksh or sed commands as well ... basically I don't want to go through a loop.

any ideas ??? ... thanks!
 
x=`tar -tf file.tar | sed 's!/[^/]*$!/!'`

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks guys ... either sed cmd works!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top