Here is a quick command that you can use to search and replace a piece of text across multiple files using find, xargs, and sed.
find . -name "*.txt" -print | xargs sed -i "s/foo/bar/g"
find . -name "*.txt" -print
This part of the command finds all of the files in the current directory that match the /*.txt/ pattern (in other words, all files that end with /.txt/.
xargs
This command is used to pass standard input to another command. It uses the single line output of the previous find command and executes the following sed command on each of the files.
sed -i “s/foo/bar/g”
This command does an /in place/ search and replace (meaning it overwrites the existing file). It uses the regular expression provided in quotes to do that replacement. In this case, replacing /foo/ with /bar/.
If you found this useful you might also like the following articles.