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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |