Artificial intelligent assistant

awk script to identify incorrect sequence of words I have a file as shown below: FHEAD01 THEAD02 TCUST03 TITEM04 TITEM05 IDISC06 TTEND07 TTAIL08 THEAD09 TCUST10 IDISC11.... TITEM12 TTEND13 TTAIL14 THEAD15 TITEM16 IDISC17 TTEND18 TTAIL19 THEAD20 IDISC21..... TITEM22 TTEND23 TTAIL24 THEAD25 TITEM26 IDISC27 IDISC28 TITEM29 TTEND30 TTAIL31 FTAIL32 I want to identify the following sequence and print records: 1) THEAD,TCUST,IDISC,* 2) THEAD,IDISC,* Expected Output Following records should be printed THEAD09 TCUST10 IDISC11 THEAD20 IDISC21 I tried the following code, but it is not giving results: awk '/THEAD/; /TCUST/ ; /IDISC/ ' test1.dat

awk '
/THEAD/{
p=$0 #store line with `THEAD`
getline #read next line from file
if(/TCUST/){ #if there is `TCUST` in it
p=p ORS $0 #add it to `p` vaiable
getline #and get next line from file
}
if(/IDISC/) #if there is `IDISC` in line
print p ORS $0 #print `p` variable altogether with line
}
' test1.dat

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 9a2065dc37c8bf92ef0dcc360a1b84ed