For example, to substitute foo with bar
for f in `grep -lR foo`; do echo -n ">> $f"; sed 's/foo/bar/g' $f > $f.tmp ; mv $f.tmp $f ; echo " done."; done
- for loops on all files containing the text “foo”, grep -l only show the file name with corresponding text inside.
- sed replace foo with bar in all file
- mv save the modification (delete if you don’t want to overwrite the original files, the modified files is named with .tmp at the end)
- & 5) echo: which file is treated