How To Batch Search and Replace Multiple Files Using PERL

Published Date Author: , Posted October 16th, 2014 at 3:28:10pm

Using PERL, we can easily do a search and replace across multiple files.

perl -pi -w -e 's/SEARCH_FOR/REPLACE_WITH/g;' FILE_LIST

The following example will replace all occurrences of “hello” with “goodbye” inside files ending with .txt:

To handle special characters, use the hex value. For example, to convert MS web files that use control characters:

perl -pi -w -e “s/\x92/’/g;” *.htm
perl -pi -w -e “s/\x96/-/g;” *.htm
perl -pi -w -e “s/\xA9/©/g;” *.htm

Works on a single file only:

No comments as yet.

Leave Your Comment  Leave a comment

All fields marked with "*" are required.