sed command to delete row

I want to use sed command to delete a matched row with a pattern.
And I also want to delete previous and next row of that row.
Which option can I use with sed ?

Hi,

To delete the matched line along with the next line, try the following

sed '/<pattern>/{N;d;}' filename

Regards,
Chella

It cann't work.

Hi,

I don't understand what do you mean by It cann't work.

Thanks,
Chella

Maybe that there is a syntax error; you might need a semicolon before the N (at least in some versions of sed). Or that it doesn't delete the preceding line as well as the next line; but that was included in the description of what it does.

anhtt: if you have a problem, please describe it so that it can be solved. "Does not work" is not sufficient information. If there is an error message, include it here. If the command does not do what you expect, describe what it does, and what you expected.

Is the requirement to do this in sed negotiable? It's fairly trivial with awk or perl, and rather tricky to do in sed.

perl -0777 -pe 's/.*\n.*<pattern>.*\n.*\n//g' file

I wrote a script "deleteEVDO" name. I want to run to command as below:
./deleteEVDO MIN

From the "MIN" variable, I want to search "MIN" in a EVDO_A12.users file.
If a row has the MIN variable, I would delete that row and one previous, one next row.

How can I do this ? Who has another way that don't use sed command ?

Perhaps maybe perchance possibly it might be worth a second of your time to try the Perl snippet I posted? Yes?

Now I have problem with sed command.

I try to use sed command with option.
sed -f /tmp/delete EVDO_A12.users
So I can delete previous and next row. But the results only display on the screen. The input file didn't change anything.Which problem ?

I'm sorry? Never heard of redirection? Are you a professional or is this an ordinary homework question?

Regards

HI I HAVE A PROBLEM,MY SOURCE FILE IS OF PATTERN
S1,E-Certified,29,29,2.7,Certified,4,3,2.7,,0,0,0
S2,Certified,4,3,2.7,,0,0,0,,0
S3,E-Certified,29,29,2.7,,0,0,0
S4,,0,0,0,,0,0,0,,0,0,0,,0,0,0

AND THE EXPECTED OUTPUT IS

S1,E-Certified,29,29,2.7
S1,Certified,4,3,2.7
S2,Certified,4,3,2.7
S3,E-Certified,29,29,2.7

THE NUMBER OF FIELDS(NF) IN SOURCE FILE MAY BE MORE THAN 500. WHEREEVER THE FIRST NULL VALUE COMES IT SHOULD TRUNCATE THE ROW.
I TRIED TO SOLVE N WROTE THIS CODE,
awk -F\, '{
if ($2!="") printf$1FS fi;c=0
for(i=2;i<=NF;i++)
{
if ($i=="") i=NF+1 fi;
printf$i ($i!=""?++c%4?i==NF?RS:FS:(i<NF?RS$1FS:RS):EXIT);
}
}'
bUT THE OUTPUT COMING IS

S1,E-Certified,29,29,2.7
S1,Certified,4,3,2.7
S1,S2,Certified,4,3,2.7
S2,S3,E-Certified,29,29,2.7
S3,

I AM NOT ABLE TO FIND OUT THE ERROR. IF ANYONE FINDS ANY PROBABLE SOLUTION PLZ SUGGEST ME.