Perl 解决方案。我把它打包成一个测试,这样你就可以……测试它。
#!/usr/bin/perl
use strict;
use warnings;
use autodie qw( open);
use Test::More tests => 1;
# I initialize the data within the test
# the real code would skip this, and open the real files instead
my $file1="raj krishna 2345 19041884
dev sri 1573 13894083
dev ravi 1232 54445434
";
my $file2="dev sri 1573 42334334
kar ham 3214 45354354
";
my $expected="raj krishna 2345 19041884
dev ravi 1232 54445434
";
my $file_out;
open( my $in1, '<', \$file1); # read from a string
open( my $in2, '<', \$file2);
open( my $out, '>', \$file_out); # write to a string
# below is the real code
# load the list of "records" to remove
# for each line take the first 3 fields (anything except a tab followed by a tab, 3 times)
my %to_remove= map { line_to_key( $_) => 1 } <$in2>;
while( my $line=<$in1>)
{ print {$out} $line unless $to_remove{line_to_key( $line)}; }
close $out;
# test whether we got what we wanted
is( $file_out, $expected, 'basic test');
# the "key": split on tab, then join the first 3 fields, again tab separated
sub line_to_key
{ my( $line)= @_;
my @fields= split /\t/, $line;
my $key= join "\t", @fields[0..2];
return $key;
}