LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   different options in sed (https://www.linuxquestions.org/questions/linux-newbie-8/different-options-in-sed-900667/)

dinakumar12 09-02-2011 01: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.

/home/dinesh/scripts

And i need to replace this with

/var/tmp/scripts.

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

Thanksin advance,
Dinesh.

David the H. 09-02-2011 02: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?).
Code:

sed 's|/home/dinesh/scripts|/var/tmp/scripts|'
Here are a few useful sed references.
http://www.grymoire.com/Unix/Sed.html
http://sed.sourceforge.net/sedfaq.html
http://sed.sourceforge.net/sed1line.txt

dinakumar12 09-02-2011 02:29 AM

Hi,

As you suugested it worked after executing this,


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

Thanks.

chrism01 09-04-2011 08:02 PM

Quote:

you could also backslash-escape them, but why bother?
Indeed; there's even an expression for the result 'Leaning toothpick syndrome' https://secure.wikimedia.org/wikiped...hpick_syndrome
:)


All times are GMT -5. The time now is 01:46 AM.