This came in handy for myself the other day and I figured it might come in handy for some of you out there. This is a quick command that will recursively do a find and replace for certain keywords by using a combination of
sed. Basically, we search recursively using
grep and then we pipe in the filenames into
sed for the string replacement.
grep -Irl keyword . | xargs sed -i 's/keyword/replacement/g'
Here’s a breakdown of the options used (I’ll assume you’re familiar with xargs and piping):
grep -I will ignore binary files
grep -r is recursive
grep -l will spit out the filename only
sed -i will edit the files in place