sed find matching pattern delete next line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed find matching pattern delete next line
# 1  
Old 12-22-2008
sed find matching pattern delete next line

trying to use sed in finding a matching pattern in a file then deleting
the next line only .. pattern --> <ad-content>
I tried this but it results are not what I wish

sed '/<ad-content>/{N;d;}' akv.xml > akv5.xml

ex,

<Celebrant2First>Mickey</Celebrant2First>
<ad-content>
Minnie & Mickey Mouse <---- delete
Join Minnie and Mickey

<Celebrant1Last>Dog</Celebrant1Last>
<EventDate>12/26/2008</EventDate>
<ad-content>
Pluto the dog <---- delete
Join Pluto for his annual dog day

-

thanks ..

akv
# 2  
Old 12-22-2008
Hi,

its "n", not "N". Try:

Command:
Code:
sed '/^<ad-content>/{n;d}'

Input:
Code:
<Celebrant2First>Mickey</Celebrant2First>
<ad-content>
Minnie & Mickey Mouse <---- delete
Join Minnie and Mickey

<Celebrant1Last>Dog</Celebrant1Last>
<EventDate>12/26/2008</EventDate>
<ad-content>
Pluto the dog <---- delete
Join Pluto for his annual dog day

Output:
Code:
<Celebrant2First>Mickey</Celebrant2First>
<ad-content>
Join Minnie and Mickey

<Celebrant1Last>Dog</Celebrant1Last>
<EventDate>12/26/2008</EventDate>
<ad-content>
Join Pluto for his annual dog day

# 3  
Old 12-22-2008
Greetings Chris ...

Thanks .... it works like a charm.

thanks,

akv
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sed: printing lines AFTER pattern matching EXCLUDING the line containing the pattern

'Hi I'm using the following code to extract the lines(and redirect them to a txt file) after the pattern match. But the output is inclusive of the line with pattern match. Which option is to be used to exclude the line containing the pattern? sed -n '/Conn.*User/,$p' > consumers.txt (11 Replies)
Discussion started by: essem
11 Replies

2. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

3. UNIX for Dummies Questions & Answers

Sed: Adding new line after matching pattern

Hi I just wanted to add a new line after every matching pattern: The method doing this doesn't matter, however, I have been using sed and this is what I tried doing, knowing that I am a bit off: sed 'Wf a\'/n'/g' Basically, I want to add a new line after occurrence of Wf. After the line Wf... (5 Replies)
Discussion started by: MIA651
5 Replies

4. UNIX for Dummies Questions & Answers

sed - combination of line deletion and pattern matching

I want to delete all the blank lines from a file before a certain line number. e.g. Input file (n: denotes line number) 1: a 2: 3: b 4: c 5: 6: d I want to delete all blank lines before line number 3, such that my output is: a b c d I see that sed '/^$/d' in_file works... (9 Replies)
Discussion started by: jawsnnn
9 Replies

5. Shell Programming and Scripting

sed or awk delete character in the lines before and after the matching line

Sample file: This is line one, this is another line, this is the PRIMARY INDEX line l ; This is another line The command should find the line with “PRIMARY INDEX” and remove the last character from the line preceding it (in this case , comma) and remove the first character from the line... (5 Replies)
Discussion started by: KC_Rules
5 Replies

6. Shell Programming and Scripting

How to use sed to modify a line above or below matching pattern?

I couldn't figure out how to use sed or any other shell to do the following. Can anyone help? Thanks. If seeing a string (e.g., TODAY) in the line, replace a string in the line above (e.g, replace "Raining" with "Sunny") and replace a string in the line below (e.g., replace "Reading" with... (7 Replies)
Discussion started by: sprinner
7 Replies

7. Shell Programming and Scripting

sed to find pattern and delete line before and after

I have the following file: line1 line2 MATCH line3 line4 I need to find the pattern, "MATCH" and delete the line before and after MATCH. So the result should be line1 MATCH lline4 I have to use sed because it is the only utility that is common across my environments. I... (1 Reply)
Discussion started by: craftereric
1 Replies

8. Shell Programming and Scripting

comment/delete a particular pattern starting from second line of the matching pattern

Hi, I have file 1.txt with following entries as shown: 0152364|134444|10.20.30.40|015236433 0233654|122555|10.20.30.50|023365433 ** ** ** In file 2.txt I have the following entries as shown: 0152364|134444|10.20.30.40|015236433 0233654|122555|10.20.30.50|023365433... (4 Replies)
Discussion started by: imas
4 Replies

9. UNIX for Advanced & Expert Users

Urgent Help required : awk/sed help to find pattern and delete till end of line

Hi, I need help with using an awk or sed filter on the below line ALTER TABLE "ACCOUNT" ADD CONSTRAINT "ACCOUNT_PK" PRIMARY KEY ("ACCT_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1) TABLESPACE "WMC_DATA" LOGGING ENABLE Look for... (1 Reply)
Discussion started by: rajan_san
1 Replies

10. Shell Programming and Scripting

Urgent! Sed/Awk Filter Find Pattern Delete Till End Of Line

Hi, I need help with using an awk or sed filter on the below line ALTER TABLE "ACCOUNT" ADD CONSTRAINT "ACCOUNT_PK" PRIMARY KEY ("ACCT_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1) TABLESPACE "WMC_DATA" LOGGING ENABLE Look for... (2 Replies)
Discussion started by: rajan_san
2 Replies
Login or Register to Ask a Question