// Source - https://stackoverflow.com/a/38972737
// Posted by fedorqui, modified by community. See post 'Timeline' for change history
// Retrieved 2025-11-22, License - CC BY-SA 3.0
awk 'flag{
if (/PAT2/)
{printf "%s", buf; flag=0; buf=""}
else
buf = buf $0 ORS
}
/PAT1/ {flag=1}' file