sed is a very handy Linux tool to search for and/or modify text. You can use it to modify the contents of files without having to manually go into them via vi.
Thanks to Stack Overflow I learned the syntax:
sed -i <filename> -e 's/<string to look for>/<string to replace it>/g'
2 thoughts on “Search and replace contents of files with sed”
vim has a built-in find a replace as well:
Indeed, it is very useful. I’ve used vim for a while to do that very thing.
Using sed from the shell comes in handy when you want to modify files in a script, as well as making it easier to copy/paste instructions instead of telling people to go into vi and execute commands. It becomes especially powerful when you combine it with find -exec.