Search this Website

 

Ubuntu

UNIX

awksed one liner for text replacement

Category: UNIX-Unix Beginner

awk/sed one liner for text replacement

hi group,

i want to replace the occurance of a particular text in a paragraph.i tried with sed,but sed only displays the result on the screen.how can i update the changes in the original file???

the solution should be a one liner using awk and sed.



you can use ">>" or ">" to redirect the results to a new file, or if you version of sed supports -i, it will update the file for you.

i want the updates in the same file......what is the -i option in sed used for???


if you have perl try this

code:
perl -i -ne ' s/search_str/replacement_str/; print ' file

thanks anbu23 and ghostdog74 for the solutions.....

we need to add a "g" in the solution provided by anbu23

code:
perl -i -ne ' s/search_str/replacement_str/g; print ' file[img]http://www.unix.com/images/buttons