The other day the boss asked me to find the e-mail address of every person who has sent mail from or that we received mail from that had a specific string in the e-mail address.. So I wrote this quick little perl script to do this.. He wanted a count and a unique list.
Here is the PERL script I wrote to do this.
#!/usr/bin/perl
my $string = shift;
while (<>)
{
m#<([^">]+(?:"[^"]+")*[^>]+)>#g;
$email = $1;
if ($email =~/$string/)
{
$count{$email}=$email;
}
}
foreach $key (sort keys(%count)) {
++$totals;
print "$count{$key}\n";
}
print "Total unique addresses with $string in them = $totals \n";Pretty simple, by using the e-mail address as the hash key, it creates a unique entry for each address found. Hashes are one of the coolest things about PERL.
usage: cat logfile.log | getcount.pl
-Fratm