Artificial intelligent assistant

Show text between 3 words on different lines from text with grep I want to show text between 3 words from text on 1 file: lalala <ticket> BASH is awesome BASH is awesome1 </ticket> lalalala <ticket> BASH is awesome2 BASH is awesome3 texttext </ticket> lololo <ticket> awesome BASH is awesome4 BASH is awesome5 </ticket> lalalla I try this: grep -Pzo '(?s)<ticket>.*\n.*awesome3.*\n.*</ticket>' file.txt Result: <ticket> BASH is awesome BASH is awesome1 </ticket> lalalala <ticket> BASH is awesome2 BASH is awesome3 texttext </ticket> lololo <ticket> awesome BASH is awesome4 BASH is awesome5 </ticket> Expects: <ticket> BASH is awesome2 BASH is awesome3 texttext </ticket>

Use the following **grep** approach:


grep -Pzo '(?s)[^<>]*?awesome3.*?' file.txt


The output:



BASH is awesome2
BASH is awesome3
texttext



* * *

`*?` \- non-greedy modifier

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 8276ead975132950d9234c7840d0c330