delete line + next line, if word match

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Dec 2008
Posts: 8
Reputation: Pender is an unknown quantity at this point 
Solved Threads: 0
Pender Pender is offline Offline
Newbie Poster

delete line + next line, if word match

 
0
  #1
Dec 12th, 2008
hi, i hope someone can help here with my problem.

i have a file with this structure:

testtt Login-Lat-Group = CNAme
Auth-Type = whatever
testt Login-Lat-Group = CName
Auth-Type = whatever
test Login-Lat-Group = CName
Auth-Type = whatever

i need now a command (e.g. awk or sed) which deletes the whole line containing the name, plus next line. but it must be exact match, deleting "test " must not end up in deleting all lines including "test" like "testt" or "testtt"

thanks in advance for any help
br, Pender
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 8
Reputation: Pender is an unknown quantity at this point 
Solved Threads: 0
Pender Pender is offline Offline
Newbie Poster

Re: delete line + next line, if word match

 
0
  #2
Dec 12th, 2008
btw: between the word to search (eg. test) and "Login-Lat-Group" is a TAB. so searching for "test<blank>" wont give the match
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 8
Reputation: Pender is an unknown quantity at this point 
Solved Threads: 0
Pender Pender is offline Offline
Newbie Poster

Re: delete line + next line, if word match

 
0
  #3
Dec 12th, 2008
i have no clue how to match the regexp for a word, followed by tab

sed '/test/d' < file ....... will delete all lines

sed '/test /d' < file ...... will not find anything

how can i check for the followed tab?
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 399
Reputation: eggi will become famous soon enough eggi will become famous soon enough 
Solved Threads: 47
eggi eggi is offline Offline
Posting Whiz

Re: delete line + next line, if word match

 
0
  #4
Dec 12th, 2008
Hey There,

You can catch tabs with sed using escape characters. So far tabs, you could match it with:

s '/test\t/d' <file
Hope that helps and best wishes,

Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,033
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 177
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: delete line + next line, if word match

 
0
  #5
Dec 13th, 2008
Originally Posted by Pender View Post
[...]
i need now a command (e.g. awk or sed) which deletes the whole line containing the name, plus next line. but it must be exact match, deleting "test " must not end up in deleting all lines including "test" like "testt" or "testtt"
Originally Posted by Pender View Post
i have no clue how to match the regexp for a word, followed by tab

sed '/test/d' < file ....... will delete all lines

sed '/test /d' < file ...... will not find anything

how can i check for the followed tab?
sed needs to be told that test is not a substring but a word: \<word_here\> will do that. Once the pattern is matched, it deletes from that line to the end of the following one.
  1. sed -e '/\<test\>/,/$/d' < filesource > filedestination
Last edited by Aia; Dec 13th, 2008 at 6:20 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 8
Reputation: Pender is an unknown quantity at this point 
Solved Threads: 0
Pender Pender is offline Offline
Newbie Poster

Re: delete line + next line, if word match

 
0
  #6
Dec 16th, 2008
thank you aia & eggi. you helped a lot.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 399
Reputation: eggi will become famous soon enough eggi will become famous soon enough 
Solved Threads: 47
eggi eggi is offline Offline
Posting Whiz

Re: delete line + next line, if word match

 
0
  #7
Dec 17th, 2008
Glad to hear it

Best wishes to you,

Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC