perl data.pl id1.txt id2.txt
A green;red;blue
B yellow;green
C red;blue;grey;pink;blank
D green;grey
blank C
blue A C
green A B D
grey C D
pink C
red A C
yellow B
print "perl $0 <id_list> <out_file>\n" and die unless(@ARGV==2);
open IN,"$ARGV[0]" or die "$!; can't open file $ARGV[0]\n";
open OUT,">$ARGV[1]" or die "$!; can't open file $ARGV[1]\n";
my%id;
my%hash;
while(<IN>){
chomp;
my@a=split(/\s/);
my@b=split(/;/,$a[1]);
$id{$a[0]}=[@b];
foreach(@{$id{$a[0]}}){
push @{$hash{$_}},$a[0];
}
}
foreach (sort keys %hash) {
print OUT "$_\t", join(' ', sort @{$hash{$_}}), "\n";
}
close IN;
close OUT;
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!