sed command to delete row


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed command to delete row
# 1  
Old 04-08-2008
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 ?
# 2  
Old 04-08-2008
Hi,

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

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

Regards,
Chella
# 3  
Old 04-08-2008
It cann't work.
# 4  
Old 04-08-2008
Hi,

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

Thanks,
Chella
# 5  
Old 04-08-2008
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.

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

# 6  
Old 04-08-2008
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 ?
# 7  
Old 04-08-2008
Perhaps maybe perchance possibly it might be worth a second of your time to try the Perl snippet I posted? Yes?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to delete line from file using sed command?

hello Team, I want to delete below linux using sed command but I am getting error.sed -i '/url=/status.cgi?hostgroup=/d' 3 error:sed: -e expression #1, char 32: unknown option to `s' Could you please help me with correct syntax. My line contain / character because of that I am getting... (4 Replies)
Discussion started by: ghpradeep
4 Replies

2. Shell Programming and Scripting

sed command to delete a pattern in a file

Hi Everyone, I have an unusual requirement. Here is where i am stuck for sometime now... I have this text file.. lets say .. output.sql... it has lot of entries... here below is part of the entry... .. . . . . . . . . . . . . . . . .... (3 Replies)
Discussion started by: vivek d r
3 Replies

3. Shell Programming and Scripting

sed command to delete everything after > on line

I have a large data file that I need to edit. There are lines like, > <IDNUMBER> (ST000002) > <SUPPLIER> (ST000002) > <IDNUMBER> (ST000004) > <SUPPLIER> (ST000004) and I need to delete everything after the >, excepting the end of line. > <IDNUMBER> > <SUPPLIER> > <IDNUMBER> > ... (4 Replies)
Discussion started by: LMHmedchem
4 Replies

4. Shell Programming and Scripting

delete the line with a particular string in a file using sed command.

Hello, I want to delete all lines with given string in file1 and the string val is dynamic. Can this be done using sed command. Sample: vars="test twinning yellow" for i in $vars do grep $i file1 if then echo "Do Nothing" else sed `/$i/d` file1 fi done Using the above... (5 Replies)
Discussion started by: PrasadAruna
5 Replies

5. Shell Programming and Scripting

sed command to delete line

HI, Im using the below commmand to delete lines having "(" at the start of a line. sed -e '/^(/d' But i need a command to delete lines that has only "(" in it and no other strings. infile - asdf asdf ( asdf ( asd outfile (1 Reply)
Discussion started by: dvah
1 Replies

6. Shell Programming and Scripting

Delete a line between selected lines using sed or any other command

I want to delete a line between selected lines using sed: e.g. : Between "bus" to "pins", delete lines conaining "signal" word. Input : bus direction signal new signal old pins signal ok end Desired Output: bus direction pins signal end (4 Replies)
Discussion started by: nehashine
4 Replies

7. Shell Programming and Scripting

SED delete only first line command - Help need

Can any one help me how the sed delete only first line command (D) works. sed -f sedcmds File.txt In this how the sed delete only first line command (D) works to delete the blank lines appearing more than ones leaving only one blank and deleting others blanks. While doing step by step when... (2 Replies)
Discussion started by: gwgreen1
2 Replies

8. Shell Programming and Scripting

deleting blank line and row containing certain words in single sed command

Hi Is it possible to do the following in a single command /usr/xpg4/bin/sed -e '/rows selected/d' /aemu/CALLAUTO/callauto.txt > /aemu/CALLAUTO/callautonew.txt /usr/xpg4/bin/sed -e '/^$/d' /aemu/CALLAUTO/callautonew.txt > /aemu/CALLAUTO/callauto_new.txt exit (1 Reply)
Discussion started by: aemunathan
1 Replies

9. Shell Programming and Scripting

sed command to delete points in a certain colum

Dear Unix users, I have a (I think simple) question; I have a file (out.dat) like below, the file contains some line which include 'LOS' string. . LOS 46.5360 91.0220 200708.2515.4900. 5400 64 1100010 . . I would like to delete the points in 4th... (4 Replies)
Discussion started by: mgunduz
4 Replies

10. Shell Programming and Scripting

SED: delete matching row and 4 next rows?

Hi, Tried to look for solution, and found something similar but could not adapt the solution for my needs.. I'm trying to match a pattern (in this case "ProcessType")in a logfile, then delete that line and the 4 following lines. The logfile looks as follows: ProcessType: PROCESS_A... (5 Replies)
Discussion started by: Juha
5 Replies
Login or Register to Ask a Question