Search and replace contents of files with sed

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”

    1. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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