Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Debian GNU/Linux Reference Guide
Prev Home Next

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.


Debian GNU/Linux Reference Guide
Prev Home Next

 
 
  Published under the terms of the GNU General Public License Design by Interspire