cajun has asked for the wisdom of the Perl Monks concerning the following question:
Jul 6 14:36:41 moe postfix/smtp[15107]: A73DC113B63: to=<oetiker@conc +entric.com>, relay=adamant.concentric.com[207.155.248.168], delay=17, + status=bounced (host adamant.concentric.com[207.155.248.168] said: 5 +54 <oetiker@concentric.com>: Recipient address rejected: Unknown or i +nvalid user oetiker@concentric.com (in reply to RCPT TO command))
Using the example above, let's say the data that I'm interested in is "A73DC113B63, 554, oetiker@concentric.com".
One way I can get this is:
My new friend Data::Dumper(::Simple) is your friend tells me:while(<FILE>){ chomp; my @text=split /:/, $_; warn Dumper(@text); }
Fine (almost). My desired information is in:@text = ( 'Jul 6 14', '36', '41 moe postfix/smtp[15107]', ' A73DC113B63', ' to=<oetiker@concentric.com>, relay=adamant.concentric.com[ +207.155.248.168], delay=17, status=bounced (host adamant.concentric.c +om[207.155.248.168] said', ' 554 <oetiker@concentric.com>', ' Recipient address rejected', ' Unknown or invalid user oetiker@concentric.com (in reply t +o RCPT TO command))' );
Thanks itub I was paying attention Re: Data::Dumper(::Simple) is your friend$text[3] and $text[5] print "($text[3])\t($text[5])\n";
Using this method I still have to remove the space in $text[3] AND do another split on $text[5], then remove the < > before my data is really what I'm looking for. And perhaps had I split differently to start with I would have better results. (I think I can see merlyn banging his head on the monitor now.)
Ok, I know what you guys and gals who do this everyday are thinking (maybe). Why didn't you use a regex and just pull out only the pieces of data that you wanted? Simple, my regex talents still suck Regex Tagging (newbie).
Perhaps the answer I'm going to get is something like, "learn to use regex and simplify your life" (hmmmmm???). Maybe not. This is the reason I'm asking. I want to know if there is a better, easier, more efficient way to accomplish the task.
Thanks,
Mike
Update: Thanks ikegami. I had been experimenting with the split since posting and was actually going to update that 'split /: /' would have been a better choice. But your way is likely better.
Thanks Kanji What I'm currently working on is customizing some SpamAssassin rules. Pflogsumm just won't give me the type of information I really need to do this.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Parsing log files (still)
by GrandFather (Saint) on Jul 06, 2005 at 21:54 UTC | |
Re: Parsing log files (still)
by ikegami (Patriarch) on Jul 06, 2005 at 21:44 UTC | |
by Kanji (Parson) on Jul 06, 2005 at 23:11 UTC |