【发布时间】:2015-04-04 15:29:06
【问题描述】:
我有两个看起来像(如下)的文件,并且想要从第二个文件中的第一个文件中查找字段,但打印第二个文件的每个字段。
#rs116801199 720381
#rs138295790 16057310
#rs131531 16870251
#rs131546 16872281
#rs140375 16873251
#rs131552 16873461
和
#--- rs116801199 720381 0.026 0.939 0.996 0 -1 -1 -1
#1 rs12565286 721290 0.028 1.000 1.000 2 0.370 0.934 0.000
#1 rs3094315 752566 0.432 1.000 1.000 2 0.678 0.671 0.435
#--- rs3131972 752721 0.353 0.906 0.938 0 -1 -1 -1
#--- rs61770173 753405 0.481 0.921 0.950 0 -1 -1 -1
我的脚本如下:
#! perl -w
my $file1 = shift@ARGV;
my @filtered_snps;
open (IN, $file1) or die "couldn't read file one";
while(<IN>){
my@L=split;
#next if ($L[0] =~ m/peak/);
push @filtered_snps,[$L[0],$L[1]];
}
close IN;
my $file2 = shift@ARGV;
my @snps;
open (IN, $file2);
while (<IN>){
my@L=split;
foreach (@filtered_snps){
if (($L[1] eq ${$_}[0]) && ($L[2] == ${$_}[1])) {
print "@L\n";
next;
}
}
}
当我应该从文件 1 中找到每一行时,我没有得到任何输出。我也尝试了 grep,但没有成功。
【问题讨论】:
标签: perl string-matching