LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   replacing string within same file (https://www.linuxquestions.org/questions/programming-9/replacing-string-within-same-file-566919/)

tostay2003 07-05-2007 03:19 PM

replacing string within same file
 
Hi,

I want to write a script in ksh, which parses the file and replaces string within it (not writing the changed text to another file).

I am able to write to another file, but don't know how to make changes within the file which is read.

theNbomr 07-05-2007 04:06 PM

This is exactly what sed specializes in.
Code:

sed -i 's/original string/replacement string/'  filename.ext
For the gory details,

man sed

--- rod.

bigearsbilly 07-06-2007 02:25 AM

or perl

perl -pi.bak -e 's/THIS/THAT/g' file ...

this creates a .bak of the original (omit when script is proven if you prefer)


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