Bigfix relevance to print previous and next lines of matching string

I have the below file content:
test.txt

Start Code
Test6
Test4
End Code

Start Code
Test1
Test2
Test3
End Code

Start Code
Test5
Test9
End Code

Requirement:
q. lines whose (it contains “Test2”) of file “test.txt”

Need to print the lines containing Test2 and the previous lines till “Start Code” & next lines till "End Code"
So the output should be:

Test1
Test2
Test3

Any idea on this would be a great help.

Thanks in advance!

This sounds.like the subject of a relevance challenge…have a look at the several methods at Relevance Challenge December 2019 BONUS: Parsing Paragraphs (answer provided) , I think one of these can help.

2 Likes

Thanks @JasonWalker!!! :slight_smile: