Feb 23, 2005 #1 Cimm Technical User Feb 17, 2005 69 US Is there any ways to do this? I am trying to format a text which contains paths. I would like to do this with sed if possible. But any other suggestions are welcome. For example /usr/local/test/log.txt wanted output test/log.txt Thanks for the help.
Is there any ways to do this? I am trying to format a text which contains paths. I would like to do this with sed if possible. But any other suggestions are welcome. For example /usr/local/test/log.txt wanted output test/log.txt Thanks for the help.
Feb 23, 2005 1 #2 futurelet Programmer Mar 3, 2004 539 US [tt] awk 'BEGIN{FS=OFS="/"}{print $(NF-1),$NF}' infile [/tt] Upvote 0 Downvote
Feb 23, 2005 Thread starter #3 Cimm Technical User Feb 17, 2005 69 US That works like a charm. Thanks Upvote 0 Downvote
Feb 23, 2005 1 #4 PHV MIS Nov 8, 2002 53,708 FR And the sed way: echo /usr/local/test/log.txt | sed 's!.*/\([^/]*/[^/]*\)!\1!' Hope This Helps, PH. Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244 Upvote 0 Downvote
And the sed way: echo /usr/local/test/log.txt | sed 's!.*/\([^/]*/[^/]*\)!\1!' Hope This Helps, PH. Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
Feb 23, 2005 Thread starter #5 Cimm Technical User Feb 17, 2005 69 US Actually, the path /usr/local/test/log.txt is in the output file. (several of them) I want to find the matching path "/usr/local/" and remove it so the output will be test/log.txt Upvote 0 Downvote
Actually, the path /usr/local/test/log.txt is in the output file. (several of them) I want to find the matching path "/usr/local/" and remove it so the output will be test/log.txt
Feb 23, 2005 #6 PHV MIS Nov 8, 2002 53,708 FR /usr/local is harcoded ? sed 's!/usr/local/!!g' /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 Upvote 0 Downvote
/usr/local is harcoded ? sed 's!/usr/local/!!g' /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
Feb 23, 2005 Thread starter #7 Cimm Technical User Feb 17, 2005 69 US Thanks. That works too. I was trying all kind of combination with s/ //g but once I put in a / to find and delete it failed. so ! has to be used for finding / and remove it? Upvote 0 Downvote
Thanks. That works too. I was trying all kind of combination with s/ //g but once I put in a / to find and delete it failed. so ! has to be used for finding / and remove it?
Feb 23, 2005 #8 PHV MIS Nov 8, 2002 53,708 FR If you insist on the / for pattern separator: sed 's/\/usr\/local\///g' /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 Upvote 0 Downvote
If you insist on the / for pattern separator: sed 's/\/usr\/local\///g' /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
Feb 23, 2005 Thread starter #9 Cimm Technical User Feb 17, 2005 69 US Thanks PHV, That's what I was looking for. Upvote 0 Downvote