Wed Dec 23 22:33:17 EST 2009

Modifying a file in place with Perl

This is documented several other places including here, but one of the really cool things you can do with command-line perl is to execute on-the-fly changes to many files though a single command line entry. For example, suppose I had 100 files with comments of # that I needed to be comments of %. I could change them all with

perl -i.orig -pe 's/\#/\%/'

My original files would now be named filename.orig and new files would exist with the change. This is a simple example, but the general idea is very powerful and very handy.


Posted by Val Schmidt | Permanent link | File under: perl