The only list of one-liners I've seen is one Tom Christiansen posted to clpm several years ago --- here is his list:

# run contents of "my_file" as a program perl my_file # run debugger "stand-alone" perl -d -e 42 # run program, but with warnings perl -w my_file # run program under debugger perl -d my_file # just check syntax, with warnings perl -wc my_file # useful at end of "find foo -print" perl -nle unlink # simplest one-liner program perl -e 'print "hello world!\n"' # add first and penultimate columns perl -lane 'print $F[0] + $F[-2]' # just lines 15 to 17 perl -ne 'print if 15 .. 17' *.pod # in-place edit of *.c files changing all foo to bar perl -p -i.bak -e 's/\bfoo\b/bar/g' *.c # command-line that prints the first 50 lines (cheaply) perl -pe 'exit if $. > 50' f1 f2 f3 ... # delete first 10 lines perl -i.old -ne 'print unless 1 .. 10' foo.txt # change all the isolated oldvar occurrences to newvar perl -i.old -pe 's{\boldvar\b}{newvar}g' *.[chy] # command-line that reverses the whole file by lines perl -e 'print reverse <>' file1 file2 file3 .... # find palindromes perl -lne 'print if $_ eq reverse' /usr/dict/words # command-line that reverse all the bytes in a file perl -0777e 'print scalar reverse <>' f1 f2 f3 ... # command-line that reverses the whole file by paragraphs perl -00 -e 'print reverse <>' file1 file2 file3 .... # increment all numbers found in these files perl i.tiny -pe 's/(\d+)/ 1 + $1 /ge' file1 file2 .... # command-line that shows each line with its characters backwards perl -nle 'print scalar reverse $_' file1 file2 file3 .... # delete all but lines beween START and END perl -i.old -ne 'print unless /^START$/ .. /^END$/' foo.txt # binary edit (careful!) perl -i.bak -pe 's/Mozilla/Slopoke/g' /usr/local/bin/netscape # look for dup words perl -0777 -ne 'print "$.: doubled $_\n" while /\b(\w+)\b\s+\b\1\b/gi' # command-line that prints the last 50 lines (expensively) perl -e '@lines = <>; print @lines[ $#lines .. $#lines-50' f1 f2 f3 .. +.

Note, I don't find the 'dup words' (second from last) one-liner terribly useful as it stands. You might want to change the -0777 to -000 to give the paragraph (and paragraph number) containing the duplicate, or if you want an actual line number so you can jump the start of the offending paragraph then you can fiddle with this one (split across two lines just for readability):

perl -000 -ne '$.=$a+1 and print "$.: doubled <$1> in\n$_\n" if /\b(\w+)\b\s+\b\1\b/gi;$a+=tr/\n//' file

In reply to Re: perl -ne (one-liners) by danger
in thread perl -ne (one-liners) by perchance

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.