linux 中 判断一列数据中指定的字符是否有连续的重复
001、
[root@PC1 test]# ls a.txt b.txt [root@PC1 test]# cat a.txt ## 测试数据a.txt gene exon gene exon exon exon exon [root@PC1 test]# awk 'BEGIN{idx=0} {if($0 == "gene") {idx++} else {idx = 0}; if(idx > 1) {print NR, "duplication"; exit}}' a.txt [root@PC1 test]# cat b.txt ## 测试数据b.txt gene exon gene exon gene gene exon [root@PC1 test]# awk 'BEGIN{idx=0} {if($0 == "gene") {idx++} else {idx = 0}; if(idx > 1) {print NR, "duplication"; exit}}' b.txt 6 duplication