I am trying to compare one or more lists against a master record file and
find out elements of the master record which are not in the other records
and compile new lists of elements which are in the master data, but not
found in the other records.

This works to fine, but the output list is random to some extend. The script
is run with command line arguments specifying the master data file and the
other file(s) to compare:

script --master masterrecord.txt --compare compare_file1 --compare
compare_file2


##########################################

#!c:\perl\bin\perl.exe -w
use strict;
#use warnings;
#use diagnostics;
use Getopt::Long;



# Perl script to compare WSUS and AV clients against AD computers and create
a report of AD
# computers not found in the WSUS or AV list.




use constant DEFAULT_REPORTDIR => 'CompareReport';
#use constant DEFAULT_WORKINGDR => '.';
my ($master, @compare, $help);


Getopt::Long::Configure ("permute","ignorecase");

GetOptions(
 "master=s" => \$master,
 "compare:s" => [EMAIL PROTECTED],
 "help|?!" => \$help,
);

usage() if $help;

foreach (@compare){
 die "File $_ does not exist or it's empty. Please check the file try
again.\n" unless -s $_;
}

my $outputdir = DEFAULT_REPORTDIR;
unless (-d $outputdir){
 mkdir ($outputdir) or die "could not create dir for $outputdir: $!\n";
}

# Read the master list and populate our array.
open (MASTERFILE, "<", $master) or die "Could not open $master for reading:
$!\n";
my @master_clients = <MASTERFILE>;
chomp(@master_clients);
close MASTERFILE;

my (%inputclient,$list);

# Read the other files and compare the content to the master client list.
foreach $list (@compare){
 # Output file name set of element curerently processed.
 # Open file to read from.

 open(INFH, "$list") or warn "Could not open $list for reading: $!\n";
 while (<INFH>){
   chomp;
   $inputclient{"$_"} = $_;
 }
 close INFH;


 my $outputfile = $list;
 my (@missing_clients, %outputclient);

  foreach my $aditem (@master_clients){
  push (@missing_clients, $aditem) unless exists $inputclient{"$aditem"};
 }


 open (OUTPUTFILE, ">$outputdir\\$outputfile") || die "Could not open
$outputfile: $!\n";
 foreach (@missing_clients){ print OUTPUTFILE "$_\n";}
 close (OUTPUTFILE);

}


# Subroutine to print example of script usage.

sub usage {
 print "\nUSAGE:\t$0 --master master_file --comapre file1 --comapre
file2\n\n";
 print "\tExample: $0 --master adlist --compare avlist --comapre file2\n";
 print "\t$0 --help or --? should displays this usage summary.\n";
 exit;

}

Reply via email to