Perl: Scroll the file and replace

I just want to read in the log file, search and replace, and then write the changes to the same log file.

What is the best way to do this in Perl?

+6
file perl substitution
Jun 01 '09 at 13:04
source share
3 answers

I usually code one liner for this:

perl -i -pe 's/some/thing/' log.file 

See here

+9
Jun 01 '09 at 13:10
source share

This is often done using a single line interface:

 perl -pi.bak -e "s/find/replace/g" <file> 

Note the -i.bak part - this creates a backup file with the extension .bak . If you want to play without a network, you can do this to overwrite an existing file without a backup:

 perl -pi -e "s/find/replace/g" <file> 
+8
Jun 01 '09 at 13:12
source share

or you can use sed (I know ... you asked about perl):

 sed -i 's/find/replace/g' <file> 
+1
Jun 01 '09 at 13:22
source share



All Articles