Grep Next Line Only If Two Lines Above Match String Consecutively
<p>I'm using the following command to match the following line in a file:</p>

<pre><code>cat file.txt | grep -A 1 'match' &gt; output.txt
</code></pre>

<p>This allows me to get the line after 'match' is found in the following file:</p>

<pre><code>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
</code></pre>

<p>However, I need to return only the lines after 2 or more consecutive 'match' lines. In this case the output would be: </p>

<pre><code>random text line 2
random text line 4
random text line 9
</code></pre>

<p>I have tried using a combination of <code>grep -A 2 'match' | grep -A 1 'match'</code> but it doesn't work as it's redundant. I'm stuck on how to match only if there are two consecutive lines. I'm open to using awk or sed for matching too if it's more efficient. Any direction would be greatly appreciated.</p>