Saturday, January 15, 2011

How to perform several changes on many files in one step

Hi,

Several time you got a very safe pattern to be modified for a different text on thousands of files on a huge hierarchical tree?   The best way I have seen this working pretty nice is with a one liner Perl, already tested on Windows, Linux and Mac, Perl still very alive!

perl -pi -e 's/this reg exp/with_this_content/g;' file

I said thousands of files but above is only one, well pipe them:

find . -name "*rb" | xargs perl -pi -e 's/this reg exp/with_this_content/g;' {}

recommendation, have a committed version of your work in case you didn't like the results of the massive editing!

No comments:

Post a Comment