-   Linux - Newbie (
-   -   different options in sed (

dinakumar12 09-02-2011 02:53 AM

different options in sed
Hi all,

I use sed to do basic string replace options in files.But i have a doubt.

Consider i have a path like this inside a file.


And i need to replace this with


I tried this with sed but failed all the time.Can any one help me to get this working through "sed".

Thanksin advance,

David the H. 09-02-2011 03:12 AM

How about showing us the actual command(s) you tried, so we can point out where you went wrong?

The most likely culprit however, is that the slashes in the text conflict with the slashes in sed's substitution command. This is easily fixed, just by using a different delimiter (you could also backslash-escape them, but why bother?).

sed 's|/home/dinesh/scripts|/var/tmp/scripts|'
Here are a few useful sed references.

dinakumar12 09-02-2011 03:29 AM


As you suugested it worked after executing this,

sed -i 's|/home/dinesh/scripts|/var/tmp/scripts/|'g file


chrism01 09-04-2011 09:02 PM


you could also backslash-escape them, but why bother?
Indeed; there's even an expression for the result 'Leaning toothpick syndrome'

All times are GMT -5. The time now is 11:08 PM.