如果下一行与模式匹配,我有删除下一行的问题。例如 :
define service{
host_name A
notification_period F
}
define service{
host_name A
notification_period metrologie
notification_period F
}
Run Code Online (Sandbox Code Playgroud)
我检查模式计量。如果下一行包含notification_period,我想删除行notification_period F。
我尝试使用命令 sed '/metrologie/{h;d;};/notification_period/{x;!d;}' $file
但它将字符串转换为:
define service{
host_name A
}
define service{
host_name A
notification_period metrologie
}
Run Code Online (Sandbox Code Playgroud)
我想要这个输出:
define service{
host_name A
notification_period F
}
define service{
host_name A
notification_period metrologie
}
Run Code Online (Sandbox Code Playgroud) sed ×1