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!

Removing Slashes with Sed 2

Status
Not open for further replies.

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.
 
That works like a charm.
Thanks
 
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
 
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
 
/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
 
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?

 
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
 
Thanks PHV,
That's what I was looking for.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top