awk 'END { if (f) print x } $0 ~ v && f++ /^--/ { if (f) print x; x = f = 0 } { x = x ? x RS $0 : $0 }' v="^IP=172.18.0.1$" file