Recent Articles

Test Environment For Perl Opens
Perl programmers, get ready - at least in a figurative sense - to break out your beakers and put on your rubber gloves, aprons, and goggles. The Comprehensive Perl Archive Network (CPAN) Testing Laboratory is good to go.

Rakudo Brings Perl 6 Closer Still
An implementation of Perl 6 on the Parrot Virtual Machine is moving forward. A fresh report indicates that Rakudo is "ready for experimentation," which is a positive...

Common Perl Criticisms Addressed
Most people know how to defend their favorite things. If you call BMWs unreliable, owners will gush about the driving experience. Say chocolate's fattening...

Iron Man Perl Blogging Challenge Begins
Type the term "Perl" into the Google Blog Search engine, and the odds seems good that you'll find the results a little disappointing. Perl just isn't discussed too...


08.18.09

Perl On The Command Line

By Jay Fougere

One of the beautiful uses of Perl is to do quick and dirty string manipulations on the command line. In a Unix environment this is especially nice as the output of one command can be piped into Perl for manipulation.

For instance, let's say that I want to view only a couple of specific fields in a log file in realtime, I can tail the log file and pipe it through a small Perl program written on the command line. As an example, let's say I want to view permanent mail delivery errors due to an invalid recipient address in a standard Postfix maillog. I could simply run:



And I would recieve some long and ugly lines that tell me more information than what I really need. Now, let's say I just want to see the addresses that are failing. I could run the same command and then pipe it through perl to grab the fields I am interested in. The '-e' flag for perl means "execute".

So Simple, So Smart. Get The Online Backup
That Gives You Both. Download a Free Trial



And I will recieve a list of the rejected email addresses.

Another favorite of mine is to strip comments from configuration files.



As you are probably aware, $_ is the current line going through the program. The three regular expressions are fairly simple. The unless statement says that if $_ begins with '#' or if $_ begins with one or more spaces followed immediately by a '#' or if $_ matches only one or more spaces, ignore the line. Otherwise we print it to standard out. You could also redirect this output to a new file name for later use



About the Author:
Jay Fougere is the IT manager for the iEntry network. He also writes occasional articles. If you have any IT questions, please direct them to Jay@ientry.com.
About PerlProNews
PerlProNews is a collection of news and commentary designed to keep you in step with the ever evolving landscape of Perl environments. News and Advice for Perl Professionals





PerlProNews is brought to you by:

SecurityConfig.com NetworkingFiles.com
NetworkNewz.com WebProASP.com
PerlProNews.com SQLProNews.com
SysAdminNews DevWebPro.com
LinuxProNews.com WirelessProNews.com
CProgrammingTrends.com ITCertificationNews.com






-- PerlProNews
is an iEntry, Inc. publication --
iEntry, 2549 Richmond Rd. Lexington KY, 40509
2009 iEntry, Inc.  All Rights Reserved  Privacy Policy  Legal

archives | advertising info | news headlines | free newsletters | comments/feedback | submit article



Database Forum News and Advice for Perl Professionals PerlProNews News Archives About Us Feedback PerlProNews.com About Article Archive News Downloads WebProWorld Forums iEntry Advertise Contact Jayde