如何删除匹配的行,上面的行和下面的行?

在nagiosconfiguration

define service{ use generic-service host_name xxx.xxx.com service_description xxx Status check_command check_http!xxx.xxx.com -S } 

我想删除整个部分,如上面给出的正则expression式匹配xxx.xxx.com 。 如何使用sed或任何其他Linux实用程序

也许这样的awk脚本:

awk -f this-script.awk my-nagios.conf> my-nagios.conf.new

 # start of block /^define/ { collecting = 1; matched = 0; buf = ""; } # end of block /}/ { collecting = 0; if (!matched) { print buf $0; }; next; } # Row in bad block /xxx.abc.com/ { if (collecting) matched = 1; } # Normal row { if (collecting) { buf = buf $0 "\n"; } else { print $0; } } 
 ed my-nagios.conf <<q w my-bagios.conf~ g/xxx.xxx.com/ ?define?,/}/d w q