Dave Emory wrote:
> Hmmm....it looks like I'm not finding all of the invalid addresses.
> I'll keep working on it.
>
> Dave
Messy, but it all seems to work now. If I were a perl programmer, it would
be a lot better (hint hint). There must be a way to do the windows findstr
function in perl, but I don't know how.
In a batch file, put this:
------------X---------------
@echo off
echo Collecting invalid email addresses from the ASSP logs...
findstr /C:"invalid address rejected: " *maillog > invalid.txt
perl de-dupe.pl
exit
------------X---------------
In de-dupe.pl, put this:
------------X---------------
#!/usr/bin/perl -w
use strict;
sub ltrim($);
# Set to filename of CSV file
my $infile = 'invalid.txt';
# Set to filename of de-duped file (new file)
my $newfile = 'recipients.txt';
my $tempfile = 'temp.txt';
my $finalfile = 'spamtrapaddresses2.txt';
### Shouldn't need to change stuff below here ###
open (IN, "<$infile") or die "Couldn't open input file: $!";
open (OUT, ">$newfile") or die "Couldn't open output file: $!";
my $log_data=undef;
my $recipient=undef;
while (<IN>) {
chomp;
($log_data,$recipient) = split(/: /);
print OUT "$recipient\n";
}
close IN; close OUT;
# Slurp in & sort everything else
my $emailaddress=undef;
my $domain=undef;
open (IN, "<$newfile") or die "Couldn't open input file: $!";
open (OUT, ">$tempfile") or die "Couldn't open output file: $!";
while (<IN>) {
chomp;
($emailaddress,$domain) = split(/\@/);
print OUT "$emailaddress\n";
}
close IN; close OUT;
open (IN, "<$tempfile") or die "Couldn't open input file: $!";
open (OUT, ">$finalfile") or die "Couldn't open output file: $!";
my @data = sort <IN>;
my $n = 0;
# Now go through the data line by line, writing it to output unless it's
identical
# to the previous line (in which case it's a dupe)
my $lastline = '';
foreach my $currentline (@data) {
next if $currentline eq $lastline;
print OUT ltrim($currentline);
$lastline = $currentline;
$n++;
}
close IN; close OUT;
print "Processing complete. In = " . scalar @data . " records, Out = $n
records\n";
# Left trim function to remove leading whitespace
sub ltrim($)
{
my $string = shift;
$string =~ s/^\s+//;
return $string;
}
------------X---------------
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Assp-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/assp-user