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