Perl Inplace Editing HOWTO

5 PM June 8, 2003

Since this is the third time in the last year I've had to look this up, I am making a note on my blog, where it should be easy for me to find :)

From this 'notes on Perl' page, how to inplace edit a file with perl:


  perl -p -i.bak -e "s#a#b#" filename

FlagMeaning
-pExecute the command(s) for every line.
-i.bakEdit the given file in-place ".bak" is the extension name of the backup file.
-eIntroduces the command to execute. The command in this case is 's' for substitute.

See also perldoc.com for information on regular expression syntax and such.

By alang | # | Comments (5)
(Posted to Software Development)
© 2003-2006 Alan Green