Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In nagios config

define service{
          use                 generic-service
          service_description xxx Status
          check_command       check_http! -S

I want to delete the entire section as given above matching regex . How to do it using sed or any other Linux utility

share|improve this question

Maybe an awk script like this:

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

# start of block
/^define/ {
  collecting = 1;
  matched = 0;
  buf = "";

# end of block
/}/ {
   collecting = 0;
   if (!matched) {
     print buf $0;

# Row in bad block
/ {
  if (collecting)
    matched = 1;

# Normal row
  if (collecting) {
    buf = buf $0 "\n";
  } else {
    print $0;
share|improve this answer
The awk script collects rows of the {} block into a variable and only prints if out on the end of the block if / is not matched. – jkj Jan 19 '12 at 8:56
ed my-nagios.conf <<q
w my-bagios.conf~
g/ ?define?,/}/d
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.