Linux command line: Search and replace in multiple files

Updated . Posted . Visible to the public.

The examples use ripgrep Show archive.org snapshot , which you probably have to install before you can use it. See the last example for how to do the same with grep.

rg -l <search-term> | xargs sed -i 's/<search-term>/<replace-term>/g'

e.g.

rg -l float-right | xargs sed -i 's/float-right/float-end/g'

rg -l will only print the file in which the search term is found.

Of course this also works with a regular grep instead of ripgrep:

grep l '<search-term>' | xargs sed -i 's/<search-term>/<replace-term>/g'
Judith Roth
Last edit
Judith Roth
Posted by Judith Roth to Judith's Dev Notes (2022-05-07 14:43)