Skip to content
Archive of entries posted on 27th January 2010

Quickly search and replace string with Regular expression in multiple files using perl

for i in *; do perl -p -w -e \’s/a(.*)b.*/d$1e/g\’  $i > temp/$i; done for i in *; do perl -pi -w -e \’s/a(.*)b.*/d$1e/g\’  $i ; done The first one can be used when you want to preserve the original file. The redirection will cause the file with replaced string to be written to the [...]