[]RSS

About Archives Artwork Comic Contact Philosophy Projects Tags

Replace in files

December 1st, 2004 in Perl. Weblog

A great one-liner:

perl -pi -e 's@foo@bar@g' *txt

This replaces instances of foo with bar in text files found in the current directory.

The -pi option is a shortcut for emulating the behaviour of tools like sed. It wraps your code in a while loop, processing the filenames passed on the command line. For more details, see the man perlrun page.

 

Leave a Reply

Subscribe to comments