Bash – awk + print lines from the first line until match word

awkbashkshlinux

I want to print all lines from file until the match word
please advice how to do that with awk

for example

I want to print all lines until word PPP

remark the first line chuld be diff from AAA ( any word )

cat file.txt

AAA   ( the first line/word chuld be any word !!!!! )
BBB
JJJ
OOO
345
211
BBB
OOO
OOO
PPP
MMM
(((
&&&

so I need to get this

AAA
BBB
JJJ
OOO
345
211
BBB
OOO
OOO
PPP

other example ( want to print until KJGFGHJ )

 cat file.txt1

 HG
 KJGFGHJ
 KKKK

so I need to get

 HG
 KJGFGHJ

Best Answer

Try:

$ awk '1;/PPP/{exit}' file
AAA
BBB
JJJ
OOO
345
211
BBB
OOO
OOO
PPP
Related Question