Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

That's why I keep a file of one-liners and here it is:

# Deparse something perl -MO=Deparse -e '' # wc -l # Clarified as per node 232599 perl -le 'print $==()=<>' file # Time to the 1000000000 rollover perl -le 'print reverse(1..9)-time' perl -le 'print 1e9-time' # Count the number of lines in a file perl -lpe'}{$_=$.' /etc/passwd # Sum the numbers in the first column of a file perl -lpe '$,+=$_}{$_=+$,' file perl -lpe '${}}+=+${_}}{${_}+=+${}}' numfile # Remove the first column perl -nale 'shift@F;print"@F"' # Get config info perl -MConfig -le 'print Config::myconfig()' perl -MConfig -le 'print $Config{startperl}' perl -MConfig=myconfig -le 'print myconfig()' perl -V:startperl # Find the version number of a module perl -le 'eval "require $ARGV[0]" and print $ARGV[0]->VERSION' Som +e::Module # Check if a module exists perl -le 'print 0 + eval "require $ARGV[0]" ' Some::Module # dos2unix perl -i -pe 's/\r//' dos.txt # JAAH perl -le 'use Inline AWK=>q+function j(){print"Just Another Awk Ha +cker"}+;j' # wc -l perl -MInline=awk,END{NR} -le 'print awk()' file # Create a slice list perl -le '@a = (0,1,2,3); @b = map {$_,$_+@a} @a; print "@b"' perl -le '@a = (0,1,2,3); @b = map {$_,$_+@a} (0..$#a); print "@b" +' # Weave 2 arrays perl -le '@a=(1,2);@b=('a','b'); @c = (@a,@b)[map {$_,$_+@a} (0..$ +#a)]; print "@c"' # Doublespace a file perl -pe '$_.=$/' file perl -00lpe 's/\n/\n\n/g' file perl -pe '$_=$/.$_ if /\S/' file.txt | cat -e # Print every line twice perl -pe '$\=$_' file # Ghost in the machine. perl -MCPAN -e 'install jmcnamara & _ x ord $ ;' | tail -1 # Last line of a file perl -pe '$*=$_}{$_=$*' file perl -e 'print+(<ARGV>)[-1]' file # tail perl -ne '$i=$.%6; $a[$i]=$_; END{print @a[$i+1..$#a,0..$i]}' file perl -ne 'END{print@a[$i+1..$#a,0..$i]}$a[$i=$.%5]=$_' file perl -ne 'END{print@a[$i+1..@a,0..$i]}$a[$i=$.%5]=$_' file perl -pe '$a[$i=$.%5]=$_}{print@a[$i+1..@a,0..$i]' file perl -pe '$_[$==$.%5]=$_}{print@_[$=+1..@_,0..$=]' file # -s perl -sle 'print $#' -- -#=3 # Print filename before line perl -pe '$_="$ARGV: $_"' file # Print filename and line number before line perl -ne 'print $ARGV,":", $., ": ", $_; $. = 0 if eof' file file2 # extract pod perl -nle 'print if /^=/ .. /^=cut/' file # extract code perl -nle 'print if not /^=/ .. /^=cut/' file # print print japh perl -e '$#="Just Another Perl Hacker$/"; print print' # print a line of a file perl -ne 'print and exit if $. == 3' file perl -ne 'print and last if $. == 3' file # grep -v perl -ne 'print if not /foo/' file perl -pe 'goto LINE if /foo/' file # Generate a random word perl -le 'print map{(a..z)[rand 26]} 0..rand 10' # print lines with only one word perl -nae 'print if @F == 1' file # Remove repeated lines perl -i.bak -ne 'print unless $h{$_}++' file sort -o thefile -u file # merlyn # remove all occurance of pattern except for the first one perl -ne 'print unless /pattern/ and $i++' file # Generate a list of months cal 2002 | perl -lane '@F==3&&print for@F' cal 2002 | perl -lane '@F==3&&print substr $_, 0, 3 for @F' # remove blank lines perl -ane '@F&&print' file perl -lp00ee file # abigail perl -llpp00ee file # abigail perl -l -00 -perl file # merlyn # BCD encode perl -le 'print join " ", map {ord pack "H2", $_} shift =~ /../g' +num # BCD decode perl -le 'print unpack "H*", pack "C*", @ARGV' num1 num2 ... perl -le 'print map {int($_/16).($_%16)} @ARGV' num1 num2 ... # Add newline to the end of a file perl -plee file1 file2 ... perl -pe '$_ .= $/ if eof and not /\n/' file1 file2 ... perl -i -pl -end file # Check a file for tabs in a file perl -ne 'die "File contains tabs.\n" if /\t/' file perl -ne 'die "File $ARGV contains tabs\n" if /\t/' file # Print a match and exit perl -ne 'print and last if /foo/' file # Exit after first match perl -ne 'print; last if /foo/' file # Exit before first match perl -pe 'last if /foo/' file perl -pe 'die $_ if /foo/' file # Count the vowels in a file perl -lne 'END{print $c} $c += tr/aeiou//' file

--
John.


In reply to Re: The problem with one-liners... by jmcnamara
in thread The problem with one-liners... by John M. Dlugosz

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!
  • 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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (17)
    As of 2015-07-06 14:56 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (76 votes), past polls