linux 中输出连续匹配字符的下一行

 

001、

[root@PC1 test03]# ls
file.txt
[root@PC1 test03]# cat file.txt       ## 测试数据
match
random text line 1
match
match
match
random text line 2
match
random text line 3
match
match
random text line 4
match
random text line 5
match
random text line 6
match
random text line 7
match
random text line 8
match
match
random text line 9                              ## 输出连续匹配字符的下一行
[root@PC1 test03]# awk '{if($0 ~ /^match$/) {count++; next}; if(count > 1) {print $0}; count = 0}' file.txt
random text line 2
random text line 4
random text line 9

 

参考:https://www.codenong.com/39600858/

 

posted @ 2023-07-07 10:35  小鲨鱼2018  阅读(21)  评论(0编辑  收藏  举报