#!/dev/null/perl -- :) use strict; my $first = shift or die "Need the first file!\n"; my $second = shift or die "Need the second file!\n"; my $third = shift or die "Need the third file!\n"; ## May as well test them all now open(FIRST, "$first") or die "Could not open $first: $!\n"; open(SECOND, "$second") or die "Could not open $second: $!\n"; open(THIRD, ">$third") or die "Could not write $third: $!\n"; my (%first, %found); while() { my ($key, @cols) = split(m#\|# => $_, -1); push(@{$first{$key}}, \@cols); $found{$key} = $.; } close(FIRST); while() { my ($one, $key, @cols) = split(m#\|# => $_, -1); if (exists $first{$key}) { delete $found{$key}; for (@{$first{$key}}) { print THIRD "$_->[0]|$one|$cols[0]\n"; } } else { printf "Line %5d: Record %5d exists in $second but not in $first\n", $.,$key; } } close(SECOND); close(THIRD); ## Double check the first file: for (sort {$found{$a} <=> $found{$b}} keys %found) { printf "Line %5d: Record %5d exists in $first but not in $second\n", $found{$_},$_; }