Friday, August 14, 2015

Replace a String in a file

trick source

Imagine you have a large file ( txt, php, html, anything ) and you want to replace all the words "ugly" with "beautiful" because you just met your old friend Sue again and she/he is coming over for a visit. This is the command:

 $ sed -i 's/ugly/beautiful/g' /home/bruno/old-friends/sue.txt

Well, that command speaks for itself "sed" edits "-i in place ( on the spot ) and replaces the word "ugly with "beautiful" in the file "/home/bruno/old-friends/sue.txt"

No comments: