我有问题,我想比较两个文件。第一个文件是参考:
ABCA4 INHR
AMT INHR
BTK ONKO1
PAP ONKO2
第二个文件用于比较:
3 1:2 T ENG1 ABCA4 ff
3 1:2 T ENG1 ABCA4 gg
5 1:4 A ENG20 AMT ll
6 1:5 G ENG12 BRB ds
7 1:6 T ENG8 PAP rg
7 1:6 T ENG8 PAP tt
我想将第一个文件中的 $1 与第二个文件中的 $5 进行比较,如果第二个文件中的 $5 和 $6 之间存在匹配,则打印第一个文件中的 $2:
3 1:2 T ENG1 ABCA4 INHR ff
3 1:2 T ENG1 ABCA4 INHR gg
5 1:4 A ENG20 AMT INHR ll
6 1:5 G ENG12 BRB - ds
7 1:6 T ENG8 PAP ONKO2 rg
7 1:6 T ENG8 PAP ONKO2 tt
所有列均以制表符分隔。
谢谢
你可以这样做:
awk 'NR==FNR{a[$1]=$2;next}{$5=$5 "\t" (a[$5]?a[$5]:"-")}1' file1 file2
details:
NR==FNR { # when the first file is processed
a[$1]=$2 # store the second field in an array with the first field as key
next # jump to the next record
}
{
$5=$5 "\t" (a[$5]?a[$5]:"-") # append a tab and the corresponding second
# field from the first file if it exists or -
}
1 # true, display the line
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)