FR

Substitute a text only in files where it appears

· 1 minute · 82 words

For example, to substitute foo with bar

for f in `grep -lR foo`; do
  echo -n ">> $f";
  sed 's/foo/bar/g' $f > $f.2;
  mv $f.2 $f;
  echo " done.";
done

Linux Shell