Replace multiple file text string using grep and perl

Jun 19

If you have a folder with a lot of files in a directory and with a specific string that you want to change you can do it in seconds using grep and perl command line:

grep -R –files-with-matches ‘OLDSTRING’ . | sort | uniq | xargs perl -pi~ -e ‘s/OLDSTRING/NEWSTRING/’

Where OLDSTRING is the string you want to find and replace with NEWSTRING.

One Response to “Replace multiple file text string using grep and perl”

  1. :!grep mudança ~/workspace/angiolumini/admin/* -R | sort | uniq | xargs perl -pi~ ‘s/mudança/Mudança/g’

    error:
    Can’t open perl script “s/mudança/Mudança/g”: No such file or directory

    and

    :!grep mudança ~/workspace/angiolumini/admin/* -R | sort | uniq | xargs perl -pi~ ‘s/mudança/Mudança/’

    Can’t open perl script “s/mudança/Mudança/”: No such file or directory

    I need help
    🙂

Leave a Reply