Languages and Scripting

Remove /dev/ from the large file using sed

 
SOLVED
Go to solution
Mike_305
Super Advisor

Remove /dev/ from the large file using sed

Hello,

I am trying to remove /dev/ from the file using sed and no luck getting that done.

If someone can hel me that will be very much appreciated.

at test.lst | sed -e 's/\/dev//' >>> Strill leaves the leading "/" and not able to remove using sed.

trying to remove /dev/ from the file

Regards,

M
If there is problem then don't think as problem, think as opportunity.
5 REPLIES 5
Patrick Wallek
Honored Contributor
Solution

Re: Remove /dev/ from the large file using sed

Here is what I started with:

$ cat test.lst
/dev/some
/dev/thing
/dev/some
/dev/thing
/dev/else

Here is what I did:

$ sed -e 's/\/dev\///g' test.lst
some
thing
some
thing
else

If you want to remove '/dev/' from the file you have to include the leading and trailing '/' characters and escape them both with the '\'.

Also note that you don't have to cat the file and pipe it to sed. That wastes a process.
Steven Schweda
Honored Contributor

Re: Remove /dev/ from the large file using sed

[...] and escape them both [...]

"/" may be less special than you think.

$ echo '/dev/thing' | sed -e 's|/dev/||'
thing
Patrick Wallek
Honored Contributor

Re: Remove /dev/ from the large file using sed

>>"/" may be less special than you think.

When you don't use the '/' as the delimiter, very true. In Steven's example above note that he used the '|' (pipe) symbol rather than forward slashes in the sed command. The eliminated the need for escaping the slashes in '/dev/'.

Mike_305
Super Advisor

Re: Remove /dev/ from the large file using sed

Thanks, appreciate the quick response and knowledge that you share.

U guys are DE Man !!!!! :)

Regards,

MJ
If there is problem then don't think as problem, think as opportunity.
Mike_305
Super Advisor

Re: Remove /dev/ from the large file using sed

thx
If there is problem then don't think as problem, think as opportunity.