Compaiting two files

From: Robert Binkley (rbinkl@comcast.net)
Date: Tue Dec 23 2003 - 12:03:23 EST


 
This can be easily done with a simple Perl script...
- - - - - - - - - - snip - - - - - - - - - -
#!/bin/perl
open(FD,"<file1") or die "could not open file1: $!\n";
while ( <FD> ) {
chomp;
$in_file1{$_} = 1;
}
close(FD);

open(FD,"<file2") or die "could not open file2: $!\n";
while ( <FD> ) {
chomp;
next if ( $in_file1{$_} );
print "$_\n";
}
close(FD);
- - - - - - - - - - snip - - - - - - - - - -
Now, if file1 looks like this:
>cat file1
Item1
Item2
Item3
Item4
and file2 looks like this:
>cat file2
Item5
Item4
Item2b
Item1
Item6
then the output of the above Perl script will look like this:
>perl perlscript
Item5
Item2b
Item6
Is that what you're looking for?
Note that this could be easily modified to accept file names on the command
line. The output could also be sorted if so desired.



This archive was generated by hypermail 2.1.7 : Sat Apr 12 2008 - 10:49:47 EDT