![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Matching fields of rows and then operating | ashis.tewari | Shell Programming and Scripting | 3 | 12-04-2008 09:02 AM |
| sum of all matching rows using awk | i.scientist | UNIX for Dummies Questions & Answers | 8 | 08-06-2008 09:13 PM |
| how to delete duplicate rows in a file | vamshikrishnab | Shell Programming and Scripting | 5 | 06-18-2008 11:00 AM |
| How to delete particular rows from a file | suresh3566 | Shell Programming and Scripting | 5 | 06-02-2008 06:07 AM |
| Delete repeated rows from a file | tonet | Shell Programming and Scripting | 8 | 04-08-2008 10:42 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
Thanks franklin, did not work for me however.. Code:
# awk '/ProcessType:/ && !p {i=-4;p=1} i++ > 0' file
awk: syntax error near line 1
awk: bailing out near line 1
With nawk it executes but only deletes the first occurrence of that "block" Code:
# nawk '/ProcessType:/ && !p {i=-4;p=1} i++ > 0' file
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
...
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|