[英]Print the row only if the string does not exist in a specific column taking account each group of strings in other column by UNIX
因此,我有以下具有數千行的列表文件:
NP_000007.1 ACADM 1457 rs1061337 not_match
NP_000007.1 ACADM 2761 rs2229249 not_match
NP_000007.1 ACADM 2761 rs2229249 not_match
NP_000019.2 AGL 1094 rs1042090 1398
NP_000019.2 AGL 1094 rs1042090 1395
NP_000057.1 C8B 1078 rs1013579 117
NP_000057.1 C8B 932 rs856847 345
NP_000057.1 C8B 932 rs856831 not_match
NP_000057.1 C8B 932 rs856841 429
NP_000076.2 CLCNKB 48 rs5251 334
如果至少在第五列中出現一次not_match模式,我想刪除在第一列中分組的每組字符串的那些行。 因此,僅打印第一列中由相同字符串分組的行,該行僅與第五列中的數字相對應。
所需的輸出將是:
NP_000019.2 AGL 1094 rs1042090 1398
NP_000019.2 AGL 1094 rs1042090 1395
NP_000076.2 CLCNKB 48 rs5251 334
我認為可以通過一些步驟將“ not_match”模式的行與第五列中的數字分隔開來,然后通過哈希查看第一列中是否存在巧合,並丟棄這些巧合。 但是,我想一步一步地在同一文件中進行操作。 我如何在Unix環境中獲得它? 提前致謝
awk
解救!
兩遍算法將是最簡單的
$ awk 'NR==FNR { # in the first round
if($NF=="not_match") a[$1]; # record the keys to be deleted
next} #
!($1 in a)' file{,} # in the second round skip them
請注意, file{,}
是file file
簡寫
NP_000019.2 AGL 1094 rs1042090 1398
NP_000019.2 AGL 1094 rs1042090 1395
NP_000076.2 CLCNKB 48 rs5251 334
替代sort
+ awk
解決方案:
sort -k1,1 -k5,5r file | awk '!($1 in a){ a[$1]=$5 }a[$1]!="not_match"'
輸出:
NP_000019.2 AGL 1094 rs1042090 1398
NP_000019.2 AGL 1094 rs1042090 1395
NP_000076.2 CLCNKB 48 rs5251 334
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.