如何在彼此之后的行上grep 2个相同的字符串

How to grep 2 same strings on lines after eachother

我想知道一段文字中是否有相似且前后相继的行。例如,我想查找是否有任何行在 eacother 中和之后具有 "cccc"。

aaaaaaaa
bbbbaaaa
ccccxxxx
ddddaaaa
eeeeaaaa
ccccxxxx   <---
ccccyyyy   <---
ddddaaaa
eeeeaaaa

所以我应该只打印双 cccc**** 行。 我试过类似的东西:

 grep "cccc" -A1 file.txt

但得到了所有 "cccc*" 行。

我知道的简单问题... 另一个例子: 搜索 "Finland" 的重复项:

Iceland
Germany
FinlandsIsNiceButNoMatch
France
FinlandWillMatchTHisTime    <---
FinlandWillAlsoMatch        <---
Hungary

这将匹配以至少 3 个相同字母开头的两行:

grep -Pzo "([a-zA-Z]{3}).*\n.*" file.txt