1개 파일의 텍스트에서 3단어 사이의 텍스트를 표시하고 싶습니다.
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
나는 이것을 시도한다:
grep -Pzo '(?s)<ticket>.*\n.*awesome3.*\n.*</ticket>' file.txt
결과:
<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>
예상하다:
<ticket>
BASH is awesome2
BASH is awesome3
texttext
</ticket>
답변1
다음을 사용하십시오grep방법:
grep -Pzo '(?s)<ticket>[^<>]*?awesome3.*?</ticket>' file.txt
산출:
<ticket>
BASH is awesome2
BASH is awesome3
texttext
</ticket>
*?
- 탐욕스럽지 않은 수식어