I have a file as shown below:FHEAD01THEAD02TCUST03TITEM04TITEM05IDISC06TTEND07TTAIL08THEAD09TCUST10IDISC11....TITEM12TTEND13TTAIL14THEAD15TITEM16IDISC17TTEND18TTAIL19THEAD20IDISC21.....TITEM22TTEND23TTAIL24THEAD25TITEM26IDISC27IDISC28TITEM29TTEND30TTAIL31FTAIL32I want to identify the following sequence and print records:1) THEAD,TCUST,IDISC,*2) THEAD,IDISC,*Expected OutputFollowing records should be printedTHEAD09TCUST10IDISC11THEAD20IDISC21I tried the following code, but it is not giving results:awk '/THEAD/; /TCUST/ ; /IDISC/ ' test1.dat
awk script to identify incorrect sequence of words
text processing;awk
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