我有这个复杂的文本文件超过22,000行:
>Cluster 35
0 2856nt, >tru_clu8_1_inde2_or1... *
>Cluster 36
0 1179nt, >gl_isotig07707... *
1 914nt, >un_isotig04557... at +/94.20%
2 1282nt, >cp_isotig06284... at -/92.43%
3 1137nt, >cp_isotig02981... at -/93.84%
>Cluster 37
0 2835nt, >yl_JTQ_com670_c0_seq1... *
>Cluster 38
0 2275nt, >pb_iso00211... at +/93.93%
1 2647nt, >yl_JTQ_com323_c0_seq1... at +/91.39%
我想要只有1次点击的群集:
>Cluster 35
0 2856nt, >tru_clu8_1_inde2_or1... *
>Cluster 37
0 2835nt, >yl_JTQ_com670_c0_seq1... *
然后,如果可能以这种格式输出:
>Cluster 35 tru_clu8_1_inde2_or1
>Cluster 37 yl_JTQ_com670_c0_seq1
答案 0 :(得分:2)
$ awk 'NR>2{if(/^>/ && b ~ /^>/) print b"\n"a} {b=a ; a=$0}' infile.txt
>Cluster 35
0 2856nt, >tru_clu8_1_inde2_or1... *
>Cluster 37
0 2835nt, >yl_JTQ_com670_c0_seq1... *
修改强>
如果有一个匹配的最终集群,则无效。此解决方法可能有效,还包括格式化输出:
$ echo ">" >> infile.txt
$ awk 'NR>2{if(/^>/ && b ~ /^>/) {a=gensub(/^.*>(\w+).*/,"\\1", "g", a) ; print b,a} } {b=a ; a=$0}' infile.txt
>Cluster 35 tru_clu8_1_inde2_or1
>Cluster 37 yl_JTQ_com670_c0_seq1
答案 1 :(得分:1)