Hi Guys,
I have a file with lots of similar records example shown at end, I want to be able to delete one of the records and have the following line of code which finds the record I need to delete, my question is now I have found the record how do I delete it and keep the rest of the file intact.
awk '{ FS="\n" ; RS="define" } /STRING/ { print }' FILENAME
e.g.
awk '{ FS="\n" ; RS="define" } /check_chris/ { print }' xeno.cfg
File
define service{
notification_interval 30
check_period 24x7
notification_options c
contact_groups unix
use generic-service
host_name xeno
service_description Check dmesg for fails
check_command check_nrpe!check_dmesg
}
define service{
notification_interval 30
check_period 24x7
notification_options c
contact_groups unix
use generic-service
host_name xeno
service_description Check Prtdiag
check_command check_nrpe!check_prtdiag
}
define service{
notification_interval 30
check_period 24x7
notification_options c
contact_groups unix
use generic-service
host_name xeno
service_description Client Version
check_command check_nrpe!check_uname
}
define service{
notification_interval 30
check_period 24x7
notification_options c
notification_options c
contact_groups unix
use generic-service
host_name xeno
service_description DNS
check_command check_nrpe!check_dns
}
define service{
notification_interval 30
check_period 24x7
notification_options c
contact_groups unix
use generic-service
host_name xeno
service_description Check NTP
check_command check_nrpe!check_ntp
}
define service{
notification_interval 30
check_period 24x7
use generic-service
host_name xeno
service_description Check Memory
check_command check_nrpe!check_mem
notification_options n
contact_groups unix
}
define service{
notification_interval 30
check_period 24x7
use generic-service
host_name xeno
service_description Check Swap
check_command check_nrpe!check_swap
notification_options n
contact_groups unix
}
define service{
notification_interval 30
check_period 24x7
use generic-service
host_name xeno
service_description Load
check_command check_nrpe!check_load
notification_options n
contact_groups unix
}
define service{
notification_interval 30
check_period 24x7
use generic-service
host_name xeno
service_description CPU
check_command check_nrpe!check_cpu
notification_options n
contact_groups unix
}
define service{
notification_interval 30
check_period 24x7
use generic-service
host_name xeno
service_description Check IO Wait
check_command check_nrpe!check_vmio
notification_options n
contact_groups unix
}
define service{
notification_interval 30
check_period 24x7
use generic-service
host_name xeno
service_description Check IO Wait
check_command check_nrpe!check_chris
notification_options n
contact_groups unix
}