Quiero mostrar texto entre 3 palabras de texto en 1 archivo:
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
Intento esto:
grep -Pzo '(?s)<ticket>.*\n.*awesome3.*\n.*</ticket>' file.txt
Resultado:
<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>
Espera:
<ticket>
BASH is awesome2
BASH is awesome3
texttext
</ticket>
Respuesta1
Utilice lo siguientegrepacercarse:
grep -Pzo '(?s)<ticket>[^<>]*?awesome3.*?</ticket>' file.txt
La salida:
<ticket>
BASH is awesome2
BASH is awesome3
texttext
</ticket>
*?
- modificador no codicioso