perl pie: substitute or change text string in lots of files from the terminal

Written by
Date: 2012-07-03 06:45:43 00:00

If you need to change a string by another in a text file, and you have a Mac or Linux powered PC with you, that is really an easy task with vim search and replace. But what if you need to search and replace that text string in a bunch of files?

Perl will rescue you this time, do not be afraid, this is just a one liner, so you do not have to get a perl book to use this simple command.

Here is an example of perl pie. Actually perl -pi -e

perl -pi -e 's/search-this-string/replace-with-this-string/g' ./*.txt

The command above will look for all txt files in the current directory and search for the string search-this-string once found, will replace all its occurrence by the text string replace-with-this-string.