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

AWK : How to extract the path within each line 1

Status
Not open for further replies.

RVSachin

Technical User
Nov 12, 2001
77
IN
awk '{print $NF}' prints the last field, but do I grep a path which is somewhere within each line that starts with a charecter //

for e.g., following line is one of the lines of my file. I need to just extract the path //mymachine/myfolder/mysubfolder
ignoring all other contents of each line.
None of the paths, or the text that follows or preceeds the path I want, are identical.

************** CODE **************

This does not exist. //mymachine/myfolder/mysubfolder {16th Mar 2005 Assigned by USER

************** CODE **************
 
Provided you haven't space in any path:
awk '/\/\//{sub(".*//","//");sub(" .*","");print}' /path/to/input > output

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks PHV! It works!
I am not too familiar with AWK.
Would you mind explaining how this works!
 
/\/\//{
find any line containing 2 consecutive /
sub(".*//","//");
get rid of all characters preceding the //
sub(" .*","");
get rid of all characters from first space
print
self explanatory

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top