The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 03-19-2009
Juha Juha is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 36
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:
Code:
ProcessType:    PROCESS_A (0) <---- delete this
SequenceNumber: 8285 <---- delete this
 <---- delete this
2009 Mar 07  22:04:23:679   0:8285 <---- delete this
 <---- delete this
ProcessType:    PROCESS_A (0)
SequenceNumber: 8286

2009 Mar 07  22:04:23:679   0:8286

ProcessType:    PROCESS_B (68)
SequenceNumber: 40689

2009 Mar 07  22:04:23:698  68:40689

DATA that should not be deleted

ProcessType:    PROCESS_B (68)
SequenceNumber: 40690

2009 Mar 07  22:04:23:698  68:40690

DATA that should not be deleted

ProcessType:    PROCESS_C (93)
SequenceNumber: 36235

2009 Mar 07  22:04:23:829  93:36235

ProcessType:    PROCESS_C (93)
SequenceNumber: 36236

2009 Mar 07  22:04:23:829  93:36236

DATA that should not be deleted
I tried this:

Code:
sed -e '/\<ProcessType\>/,/$/d' < log.txt > test
But that only resulted in this:

Code:
2009 Mar 07  22:04:23:679   0:8285


2009 Mar 07  22:04:23:679   0:8286


2009 Mar 07  22:04:23:698  68:40689


2009 Mar 07  22:04:23:698  68:40690


2009 Mar 07  22:04:23:829  93:36235


2009 Mar 07  22:04:23:829  93:36236


2009 Mar 07  22:04:23:945  91:89062


2009 Mar 07  22:04:23:945  91:89063


2009 Mar 07  22:04:24:018  91:89064


2009 Mar 07  22:04:24:018  91:89065


2009 Mar 07  22:04:24:018  91:89066