Get updates via: rss | twitter | email

Replace with sed

Written by
Date: 2014-11-29 11:05:20 00:00

How to replace strings with sed

**Q. How can I replace a word with another without "opening" file on the fly with sed?

A. Sed is a wonder and powerful stream *editor, and with it you can make modifications to files from the command line.

Replace with sed

sed 's/old/new/g' file.txt

That will output the file to the screen with all occurences of old changed to new, if you want to replace and save the file in one step.

sed -i '' 's/old/new/g' file.txt

This last one will open the file, replace and save the file again.