Perl and regular expressions
Hi All,
I have a server which scans all inbound and outbound email for virus infected files. I am able to get it to generate reports, i.e tell me all messages which the server accepted. and it will then generate a csv file with the following format.
Date, Time, Action, Result, Client, Server, From, To, To, To....., Subject, Size, SMTP ID
a typical line might be
20021101,0,MessageAccepted,,10.0.0.1,,[email protected],[email protected],[email protected],Subject,........
I need to use regular expressions in perl to scan these reports for mail from a particular domain to a particular domain. i.e. from [email protected] to [email protected]. So, I need it to only give a match if the domain after the sixth comma is @domain.com, and only if. I have the following code which does match that requirement, except that if there are multiple recipients in domain.com, and the sender is not in domain.com it will also match, not what I need.
Anyway, here is the code I am using, I hope that someone can point me in the right direction to specify the 6 comma requirement exactly, using regular expressions, or some other way which I haven't learned yet. (Only been doing perl for about 2 days now...)
#!/usr/bin/perl
#this next line reads stdin, call the script like (perl script.pl filename)
while (<>) {
# the next line is a regular expression, attempting to specify random text then comma,
#six times before domain.
if (/^.*,.*,.*,.*,.*,.*,.*\@domain.com,.*\@domain.com/){
# output data to screen
print;
}
}
Thanks in advance,
IchNiSan