8.6.20 Perl short script madness
Although any Awk scripts can be automatically rewritten in Perl using
a2p(1)
, one-liner Awk scripts are best converted to one-liner perl
scripts manually. For example
awk '($2=="1957") { print $3 }' |
is equivalent to any one of the following lines:
perl -ne '@f=split; if ($f[1] eq "1957") { print "$f[2]\n"}' |
perl -ne 'if ((@f=split)[1] eq "1957") { print "$f[2]\n"}' |
perl -ne '@f=split; print $f[2] if ( $f[1]==1957 )' |
perl -lane 'print $F[2] if $F[1] eq "1957"' |
Since all the whitespace in the arguments to perl
in the line
above can be removed, and taking advantage of the automatic conversions between
numbers and strings in Perl:
perl -lane 'print$F[2]if$F[1]eq+1957' |
See perlrun(1)
for the command-line options. For more crazy Perl
scripts, https://perlgolf.sourceforge.net
may be interesting.