• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 825
  • Last Modified:

perl - compare list

I have two files that both have a list of email addresses in them

1) org-list.txt
2) new-list.txt

I need to find what address is in the new-list.txt that is not in the org-list.txt

I can do that with this code I use:


#!/usr/bin/perl
use strict;
my($file1,$file2);

my %file1;
open (FILE1, "<org-list.txt");
while(<FILE1>) {
 $file1{lc $_}=1;
}
close(FILE1);

open (FILE2, "<new-list.txt");
while (<FILE2>) {
  unless ($file1{lc $_}) {
    print $_;
  }
}


=====================================

I have the org-list.txt already made and I can make the new-list.txt using this code I use:


!/usr/bin/perl
use strict;
open(FH,"</mail/logs/users.txt");
while (<FH>){
$_=lc;
chomp;
        my ($domain) = (/From:.*?<.*slb.com>/i);
        my ($from) = (/X-Mailer: .*Message-ID:.*<.*abc.com> From:.*<(.*?)>/i);
        my ($outlook) = (/X-Mailer: .*(Outlook)/i);
        if($domain and $outlook and $from) {
          print "$from\n";
        }
}


=====================================


I can create the new list as show above then run the first code to get what I want, but where I'm stuck now is putting this together, not just sure how to do this.

I need to edit the second code so it will get the new list of address, sort unique them, put that list in a % then compare each mail address with the list that is in the org-list.txt, if any address is found on the new-list that is NOT in the org-list.txt then print that out.

Hope this explanation came out ok.


I have want I want working, I'm just looking to learn a bit more and combine the two scripts I'm using so I can run the second code above that gets my new list then compares with the org-list.txt so I can do this in one step instead of two.


Thanks for any help.
0
bt707
Asked:
bt707
1 Solution
 
ozoCommented:
#!/usr/bin/perl
use strict;

my %file1;
open (FILE1, "<org-list.txt");
while(<FILE1>) {
 chomp;
 $file1{lc $_}=1;
}
close(FILE1);

my %file2;
open(FH,"</mail/logs/users.txt");
while (<FH>){
$_=lc;
        my ($domain) = (/From:.*?<.*slb.com>/i);
        my ($from) = (/X-Mailer: .*Message-ID:.*<.*abc.com> From:.*<(.*?)>/i);
        my ($outlook) = (/X-Mailer: .*(Outlook)/i);
        if($domain and $outlook and $from and !$file1{$from} ) {
           $file2{$from}++
        }
}
close FH;

print "$_\n" for sort keys %file2;
0
 
bt707Author Commented:
ozo,

Worked perfect.

Thank you very much!!
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now