awk:打印与文件中的模式不匹配的行,查看特定列
我有一个awk:打印与文件中的模式不匹配的行,查看特定列,awk,pattern-matching,bioinformatics,text-processing,Awk,Pattern Matching,Bioinformatics,Text Processing,我有一个idFile: 1006006 1006008 1006011 1007002 ...... 1006 1006001 1006016 1006017 1 1006 1006006 1006016 1006017 1 1006 1006007 0 0 2 1006 1006008 1006007 1006006 2 1006 1006010 1006016 1006017 2 1006 1006011 1006016 1006017 1 1006 1006
idFile
:
1006006
1006008
1006011
1007002
......
1006 1006001 1006016 1006017 1
1006 1006006 1006016 1006017 1
1006 1006007 0 0 2
1006 1006008 1006007 1006006 2
1006 1006010 1006016 1006017 2
1006 1006011 1006016 1006017 1
1006 1006016 0 0 2
1006 1006017 0 0 1
1007 1007001 1007950 1007015 2
1007 1007002 1007014 1007015 2
......
和famFile
:
1006006
1006008
1006011
1007002
......
1006 1006001 1006016 1006017 1
1006 1006006 1006016 1006017 1
1006 1006007 0 0 2
1006 1006008 1006007 1006006 2
1006 1006010 1006016 1006017 2
1006 1006011 1006016 1006017 1
1006 1006016 0 0 2
1006 1006017 0 0 1
1007 1007001 1007950 1007015 2
1007 1007002 1007014 1007015 2
......
我需要grepfamFile
中的所有行,其中第二列与idFile
中的任何行都不匹配
但是如何修改该命令以获得匹配项的补充
$ awk 'NR==FNR{a[$1];next} !($2 in a)' idFile famFile
1006 1006001 1006016 1006017 1
1006 1006007 0 0 2
1006 1006010 1006016 1006017 2
1006 1006016 0 0 2
1006 1006017 0 0 1
1007 1007001 1007950 1007015 2
解释:
$ awk '
NR==FNR { # process the idFile
a[$1] # hash to a
next # next id
}
!($2 in a) # if the second field id is not in a, output record
' idFile famFile # mind the file order
解释:
$ awk '
NR==FNR { # process the idFile
a[$1] # hash to a
next # next id
}
!($2 in a) # if the second field id is not in a, output record
' idFile famFile # mind the file order
a==0中的$2与相比是奇数语法!(a中的$2)
a中的$2==0
与相比是奇数语法!(一个$2)
。你发布的命令有问题。我想教训是要警惕从一篇题为“unix for dummies”的参考文章中得到的任何脚本!有关何时/如何正确使用getline的信息,请参阅。您发布的命令有问题。我想教训是要警惕从一篇题为“unix for dummies”的参考文章中得到的任何脚本!有关何时/如何正确使用getline的信息,请参阅。