in reply to search a string and get the output that belongs to the string
Hello theravadamonk,
It’s simpler if you read in a whole message (four lines: Message Time, Mail From, Mail to, quarantine) at a time, and then search for “jay” in one of the addresses. Here is one approach:
#! perl use strict; use warnings; use Data::Dump; my @message; READ_FILE: while (<DATA>) { push @message, $_; for (1 .. 3) { last READ_FILE unless defined(my $line = <DATA>); push @message, $line; } if ($message[1] =~ /<jay@/i || # Mail From: $message[2] =~ /<jay@/i) # Mail to: { print "\n", join('', @message); } @message = (); } __DATA__ Message Time: Feb 3 11:24:54 Mail From: <letter@leemaletter.com> Mail to: <info@example.com>,<jay@example.com> quarantine: spam-JF6LBytcy_3D.gz Message Time: Feb 3 11:25:18 Mail From: <noreply@lankaemarketing40.info> Mail to: <jay@example.com> quarantine: spam-uXWM3SJ-nlB0.gz Message Time: Feb 3 11:25:29 Mail From: <bounce@rhmarketing.info> Mail to: <sam@example.com> quarantine: spam-uOG8ycqZrq1s.gz Message Time: Feb 3 11:25:47 Mail From: <Jay@example.com> Mail to: <userx@gmail.com> quarantine: spam-FxfQDEDm-5MW.gz
Output:
12:51 >perl 1624_SoPW.pl Message Time: Feb 3 11:24:54 Mail From: <letter@leemaletter.com> Mail to: <info@example.com>,<jay@example.com> quarantine: spam-JF6LBytcy_3D.gz Message Time: Feb 3 11:25:18 Mail From: <noreply@lankaemarketing40.info> Mail to: <jay@example.com> quarantine: spam-uXWM3SJ-nlB0.gz Message Time: Feb 3 11:25:47 Mail From: <Jay@example.com> Mail to: <userx@gmail.com> quarantine: spam-FxfQDEDm-5MW.gz 12:51 >
Notes:
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: search a string and get the output that belongs to the string
by theravadamonk (Scribe) on May 31, 2016 at 10:39 UTC |