Perl - One Liners

perl

perldoc perlrun

How to print lines of the selected files between the START and END markers, without printing the markers themselves?

perl -ne 'print if s/^START\n$// .. s/^END\n$//' files...

How to print lines following (and including) a line that matches a pattern?

perl -ne '$i = 1 if /pattern/; print if $i--' files

How to replace Windows line terminators with Unix line terminators?

perl -i -pe 's/\r\n/\n/g' /usr/share/vim/vim63/ftplugin/pdoc4vim.vim

How to search filename for all instance of sysread and replace them with read?

perl -p -i -e 's/sysread/read/g' filename

How to execute a string of perl code from command line?

perl -e 'print "Hello World\n"'

What are the important switches?

-e: indicates that the entire program is provided right there on the command line
-n: add a loop around your -e code.
-i: cause any changes to be written back to the file when done

How to read a file (input.txt) line by line and extract out matching part of the line match the specified pattern?

perl -ne 'print "$1\n" if /Binary files my_quantros.war(.*?) and production_quantros.war\1 differ/' input.txt
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License