日期:2014-05-16 浏览次数:20676 次
#!/usr/bin/perl use strict; use warnings; my %samples; open my $fh, '<', 'sample.txt' or die $!; while (<$fh>) { chomp; $samples{$_} = 1; } close $fh or die $!; open my $res, '>', 'result.txt' or die $!; open $fh, '<', 'data.txt' or die $!; while (<$fh>) { if (/^(\d+)/) { do {print $res $_;} if $samples{$1}; } } close $fh or die $!; close $res or die $!;
------解决方案--------------------
awk 'NR==FNR{a[$1]=$0;next}{if($1 in a)print $1FS$2}' sample.txt data.txt