delete line help

$ cat testf
line one
 
sec begin
id=25
details=ax
status=y
sec end
 
sec begin
id=26
details=ay
status=n
sec end
 
sec begin
id=28
details=am
status=n
sec end
 
last line

I had to delete the para which is having "id=26", this is what I did

$ sed '/id=26/{N;N;N;d;}' testf
 
o/p:
 
line one
 
sec begin
id=25
details=ax
status=y
sec end
 
sec begin
 
sec begin
id=28
details=am
status=n
sec end
 
last line

How can I delete the whole paragraph (from "sec begin" to "sec end") where "id=26" is present. i.e.
required output:

line one
 
sec begin
id=25
details=ax
status=y
sec end
 
sec begin
id=28
details=am
status=n
sec end
 
last line
sed ':_
/begin/,/end/{
  /end/!{
    $!{
      N
      b_
    }
  }
/id=26/d;
}' infile

Another one with awk:

awk '
/begin/{s="";v=0}
{s=s?s "\n" $0:$0}
/id=26/{v=1}
/end/ && !v {print s "\n"}
' file

Regards

Both the solutions worked fine, thanks a lot.

But I am unable to supply a variable with double quote in the sed solution above.

e.g.
 
$ var=26 
$ sed ":_
/begin/,/end/{
  /end/!{
    $!{
      N
      b_
    }
  }
/id=$var/d;
}" testf
 
The above is not working. How can I supply a part of the pattern as variable, please help.

grep -vp "id=26"

-v means exclude
-p means paragraph (If this switch doesn't work with grep on your OS, you may have to use egrep)

Try this:

sed ':_
/begin/,/end/{
  /end/!{
    $!{
      N
      b_
    }
  }
/id='"$var"'/d;
}' file
#! /usr/bin/perl
$/="\n\n";
open FH,"<a.txt";
while(<FH>){
	print $_ unless m/id=26/;
}