Perl “One-Liners”
Posted on maart 21, 2008
Filed Under Perl One-Liners
Perl “One Liners” are -surprise surprise- little perl programs written on one line.
Here are a few simple examples :
Guess what this one does
$ perl -e 'print "Hello";' -e 'print " World\n"'
DOS to Unix text convert
$ perl -i -pe 's/\r//g' file
Unix to DOS text convert
$ perl -i -pe 's/\n/\r\n/' file
‘Fun’ with columns:
$ echo a b c | perl -lane 'print $F[1]'
b
$ echo a b c | perl -lane 'print "@F[0..1]"'
a b
$ echo a b c | perl -lane 'print "@F[-2,-1]"'
b c
More one-liners will follow…
Comments
Leave a Reply
You must be logged in to post a comment.