001、
[root@PC1 test02]# ls a.txt [root@PC1 test02]# cat a.txt ## 测试数据 333 kkk gene 777 1 333 kkk exon 777 2 333 kkk exon 777 3 333 kkk gene 777 4 333 kkk exon 777 5 333 kkk gene 777 6 333 kkk gene 777 7 333 kkk gene 777 8 333 kkk exon 777 9 333 kkk exon 777 9 [root@PC1 test02]# awk 'BEGIN{sum = 0} {if($3 == "gene") {sum++} else {sum = 0}; if(sum > 1) {print NR - 1; print NR}}' a.txt 6 7 7 8 ## 输出第三列指定字符 gene 有连续重复的行号 [root@PC1 test02]# awk 'BEGIN{sum = 0} {if($3 == "gene") {sum++} else {sum = 0}; if(sum > 1) {print NR - 1; print NR}}' a.txt | uniq 6 7 8
。
标签:字符,777,sum,333,行号,exon,kkk,linux,gene From: https://www.cnblogs.com/liujiaxin2018/p/17515750.html