Unix Program Sed Useful Making Simple Substitutions Throughout Entire File One Limitations Q37076498

The Unix program sed is useful for making simple substitutionsthroughout an entire file. But one of its limitations is that italways puts its results onto standard output and therefore itcannot be used to edit a file “in place”. For example, thecommand

sed s/foo/bar/g myFile.txt

will replace every occurrence in myFile.txt of the string “foo”by the string “bar”, with the altered file appearing at thestandard output (i.e., scrolling by on your terminal screen). Butwhat if you really wanted to make this change tomyFile.txt?

We could do this in two steps:

mv myFile.txt myFile.txt.baksed s/foo/bar/g myFile.txt.bak > myFile.txt

(…) three command-line parameters:

-the string to be replaced

-the string

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.