Good Day Everyone,
I’m currently trying to write a routine that will examine a file for a particular unique string, then delete the entire encapsulated text as follows:
define service{
use generic-service,srv-pnp
host_name MEVIE.COM
service_description NSClient++ Version
check_command check_nt!CLIENTVERSION
}
There’s many instances of define service { ... } in the file. So I can’t just search on define service, I have to search on the unique string then delete the entire define service { ... } encapsulation.
For example:
- Find the string “NSClient++ Version” in the file…
- Delete EVERYTHING within
define service{ .... } - Delete
define service { .... }tags as well.
I really hope my goal is clear.
I’ve tried: sed -n '/NSClient+++ Version/{H;g;p};H' MEVIE.bak|tail -n5 > mevie.fil .. it returns everything except the last ‘}’
Here’s one way using
sed. Run like:Contents of
script.sed:Alternatively, here’s the one-liner: