Then, reading "file 2", only print a line if its first token does not exist as a hash key. These are the records in file 2 that do not exist in file 1.
Put that way, the script can be very short, especially if you just give the file names as command line args:
That will print the targeted records to STDOUT, which you can redirect to a file via the command line:use strict; die "Usage: $0 file.1 file.2\n" unless ( @ARGV == 2 ); # test for number of args my %known; open( F, "<", $ARGV[0] ) or die "$ARGV[0]: $!"; while (<F>) { chomp; $known{$_} = undef; # don't need a value, just the key } close F; open( F, "<", $ARGV[1] ) or die "$ARGV[1]: $!"; while (<F>) { my $key = ( split ' ', $_ )[0]; # get first "word" print unless exists( $known{$key} ); } close F;
(update: just noticed that this is identical to TedPride's suggestion, ignoring a few trivial, irrelevant differences. sorry about the redundancy)little_perl_script.pl file.1 file.2 > target.set
In reply to Re: Seeking guidance on how to approach a task
by graff
in thread Seeking guidance on how to approach a task
by mark_nelson
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |