awk ' BEGIN { FIRST=0 } { if(FIRST==1){ if(match($0, "Shutting down connection to server")){ print "matched ok" exit 0 } else { print "not matched ok" exit 1 } } else { if(match($0, "Updating collection ")) { FIRST=1 next } } }'