在 nagios 配置中
define service{
use generic-service
host_name xxx.xxx.com
service_description xxx Status
check_command check_http!xxx.xxx.com -S
}
我想删除上面匹配正则表达式的整个部分xxx.xxx.com. 如何使用sed或任何其他 Linux 实用程序
答案1
也许是这样的 awk 脚本:
awk -f 这个脚本.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;
}
}
答案2
ed my-nagios.conf <<q
w my-bagios.conf~
g/xxx.xxx.com/ ?define?,/}/d
w
q