I am parsing through /var/log/mail.log via regexp and I need to skip date lines that are NOT followed by to|from|connect. Here is my code:
use strict; use warnings; mailog = "/var/log/mail.log"; open (MAIL, "+<$mailog") or die $!; foreach (<MAIL>) { chomp; my $datestr =~ (/^.{15}/); my $mailmsg =~ (/^.?connect\sto.*|to=.*|host.*$/); print $datestr,"\n",$mailmsg; } close (MAIL); The output of this code is below and I DO NOT want, can skip the outpu +t such as Mar 21 18:58:08 Mar 21 18:58:08 Mar 21 18:58:08 I only want ouput IF the date is followed by to=|connect\sto.*|host.* __OUTPUT__ to=<colossus1821@juno.com>, relay=mx.dca.untd.com[64.136.44.37]:25, delay=177323, delays=177322/0.02/1.8/0, dsn=4.0.0, status=deferred (ho +st mx.dca.untd.com[64.136.44.37] refused to talk to me: 550 Access denied...0b30748490a5c4c48900e4e9912059c0e18d1d24dd45d1896d5150b1f1755 +1f975b124c9b1b12499b11974d1d44099f4d135f440c46d305d...) Mar 21 18:58:08 Mar 21 18:58:08 Mar 21 18:58:08 to=<scottw@webav.com>, relay=none, delay=187566, delays=187536/0.05/30/0, dsn=4.4.1, status=deferred (connect to webav.com[74.117.116.83]:25: Operation timed out) Mar 21 18:58:08 to=<stevew@webav.com>, relay=none, delay=187566, delays=187535/0.02/30/0, dsn=4.4.1, status=deferred (connect to webav.com[74.117.116.83]:25: Operation timed out) Mar 21 18:58:08 Mar 21 18:58:08 to=<ssams@phoenixformations.com>, relay=none, delay=187576, delays=187546/0.02/30/0, dsn=4.4.1, status=deferred (connect to mail.phoenixformations.com[69.61.147.50]:25: Operation timed out)

In reply to a regexp? by Anonymous Monk

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, 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.