Showing posts with label perl command line. Show all posts
Showing posts with label perl command line. Show all posts

Thursday, March 31, 2016

Single command to replace string in Perl

Ref:
https://techome.wordpress.com/2007/12/22/perl-commandline-search-and-replace/
http://www.atrixnet.com/in-line-search-and-replace-in-files-with-real-perl-regular-expressions/


C:\strawberry\perl\bin\perl.exe -pe "s/\\audio_hole_log\\/\\audio_hole_log/g" 

-e option allows you to define Perl code to be executed by the compiler. For example, it’s not necessary to write a “Hello World” program in Perl when you can just type this at the command line.
# perl -e ‘print “Hello World\n”‘
-p option, adds loops around your -e code.It creates code like this:
LINE:
while (<>) {
# your code goes here
} continue {
print or die “-p destination: $!\n”;
}
-i option. Actually, Perl renames the input file and reads from this renamed version while writing to a new file with the original name. If -i is given a string argument, then that string is appended to the name of the original version of the file. For example, to change all occurrences of “PHP” to “Perl” in a data file you could write something like this:
# perl -i -pe ‘s/PHP/Perl/g’ file.txt