Perhaps Perl's (5.10+) given/when will work for you:
use Modern::Perl; while ( my $string = <DATA> ) { given ($string) { when (/<=/) { say '<= was found.'; } when (/=>/) { say '=> was found.'; } when (/==/) { say '== was found.'; } when (/\*\*/) { say '** was found.'; } default { say "The following was found: $_"; } } } __DATA__ May 2 07:06:20 lon.mail.net exim[1234]: 2012-05-02 07:06:20 1PSPtU-00 +04en-1e <= it_ndt_bounces@new.itunes.com H=smtpmail.com [21.5.10.4] I +=[8.4.14.4]:25 P=esmtp S=1966 id=1603882764.112965659.1335927964793.M +ail.cboxp@ednabay.apple.com T="New on iTunes: One Thing And, Then Ano +ther, Cooking Apps,\n Great Deals on First Seasons, and M" May 2 07:06:20 lon.mail.net exim[1234]: 2012-05-02 07:06:20 1PSPtU-00 +04en-1e <= it_ndt_bounces@new.itunes.com H=smtpmail.com [21.5.10.4] I +=[8.4.14.4]:25 P=esmtp S=1966 id=1603882764.112965659.1335927964793.M +ail.cboxp@ednabay.apple.com T="New on iTunes: One Thing And, Then Ano +ther, Cooking Apps,\n Great Deals on First Seasons, and M" May 2 07:06:20 lon.mail.net exim[1235]: 2012-05-02 07:06:20 1PSPtU-00 +04en-1e => peterpiper <peterpiper@nosuchdomain.net> R=local_mail T=lo +cal_maildir_mail_drop May 2 07:06:20 lon.mail.net exim[1235]: 2012-05-02 07:06:20 1PSPtU-00 +04en-1e == peterpiper <peterpiper@nosuchdomain.net> R=local_mail T=lo +cal_maildir_mail_drop May 2 07:06:20 lon.mail.net exim[1234]: 2012-05-02 07:06:20 1PSPtU-00 +04en-1e ** it_ndt_bounces@new.itunes.com H=smtpmail.com [21.5.10.4] I +=[8.4.14.4]:25 P=esmtp S=1966 id=1603882764.112965659.1335927964793.M +ail.cboxp@ednabay.apple.com T="New on iTunes: One Thing And, Then Ano +ther, Cooking Apps,\n Great Deals on First Seasons, and M" May 2 07:06:20 lon.mail.net exim[1235]: 2012-05-02 07:06:20 1PSPtU-00 +04en-1e -- peterpiper <peterpiper@nosuchdomain.net> R=local_mail T=lo +cal_maildir_mail_drop
Output:
<= was found. <= was found. => was found. == was found. ** was found. The following was found: May 2 07:06:20 lon.mail.net exim[1235]: 2012 +-05-02 07:06:20 1PSPtU-0004en-1e -- peterpiper <peterpiper@nosuchdoma +in.net> R=local_mail T=local_maildir_mail_drop
Hope this helps!
Update: My thanks to influx for pointing me to an article in which the author encourages programmers to Use for() instead of given(). This may be especially relevant in this case, where millions of lines could be processed.
In reply to Re: Process mail logs
by Kenosis
in thread Process mail logs
by stevbutt
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |