为列的每个唯一值输出整行一次(Bash)

这肯定是awk或其他方面的一项微不足道的任务,但它让我今天早上挠头.我有一个格式与此类似的文件
pep> AEYTCVAETK     2   genes ADUm.1024,ADUm.5198,ADUm.750
pep> AIQLTGK        1   genes ADUm.1999,ADUm.3560
pep> AIQLTGK        8   genes ADUm.1999,ADUm.3560
pep> KHEPPTEVDIEGR  5   genes ADUm.367
pep> VSSILEDKTT     9   genes ADUm.1192,ADUm.2731
pep> AIQLTGK        10  genes ADUm.1999,ADUm.3560
pep> VSSILEDKILSR   3   genes ADUm.2146,ADUm.5750
pep> VSSILEDKILSR   2   genes ADUm.2146,ADUm.5750

我想在第2列中为每个不同的肽值打印一行,这意味着上面的输入将成为:

pep> AEYTCVAETK     2   genes ADUm.1024,ADUm.2731
pep> VSSILEDKILSR   3   genes ADUm.2146,ADUm.5750

这是我到目前为止所尝试过的,但显然我也不需要:

awk '{print $2}' file | sort | uniq
# Prints only the peptides...
awk '{print $0,"\t",$1}' file |sort | uniq -u -f 4
# Altogether omits peptides which are not unique...

最后一点,它需要将作为其他肽的子串的肽作为不同的值处理(例如VSSILED和VSSILEDKILSR).谢谢 :)

使用awk的一种方法
awk '!array[$2]++' file.txt

结果:

pep> AEYTCVAETK     2   genes ADUm.1024,ADUm.5750

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...