delete lines between patterns

Hi, I've searched in this forum all day long but was not able to find enough codes to help me do a task. The only code that I can come up with is this:

sed '/[0-9] [0-9] /,/[0-9] [0-9] /{//p;d;}' inputfile > outputfile

I would like to sed/awk/grep a file for two patterns and then delete the lines between those patterns. Please see the inputfile below. This is just a small portion of a lengthy file. Everything in bold should be deleted.

In this case, I would like to search for the first pattern [0 0 2] and the last pattern [2433 2433 2], then delete every line between these patterns but keeping the line [ANT_2] above the line [2433 2433 2]. Similarly, I would like to search for the first pattern [0 0 4] and the last pattern [1 1 2], then delete every line between these patterns but keeping the line [ANT_6] above the line [1 1 2]. The number of lines between these pattens can vary. The only thing that I can see that is constant is the [0 0 ].

Any help or suggestion would be greatly appreciated.

inputfile
--------
ANT_1
0 0 2 Jan 14 10:11:44 2009
Rule File Pathname: /home/la/_drc_
ply to gate area ratio > 500
ANT_2
2433 2433 2 Jan 14 10:13:46 2009
Rule File Pathname: /home/la/_drc_
mt1 to gate area ratio > 40
p 1 44
-2109300 -10645700
-2095600 -10645700
-2095600 -10649700
-2088500 -10649700
-2088500 -10655700
-2071900 -10655700
ANT_3
0 0 2 Jan 14 10:13:59 2009
Rule File Pathname: /home/la/_drc_
mt2 diff gate inputs.
ANT_4
0 0 2 Jan 14 10:14:01 2009
Rule File Pathname: /home/la/_drc_
gold diff gate inputs.
ANT_5
0 0 4 Jan 14 10:14:01 2009
Rule File Pathname: /home/la/_drc_
gold diff gate inputs.
ANT_6
1 1 2 Jan 14 10:14:01 2009
Rule File Pathname: /home/la/_drc_
gold diff gate inputs.
NET_AREA_RATIO_RDBS
0 0 3 Jan 14 10:14:01 2009
ANT2.OUT
ANT3.OUT
ANT4.OUT

Desired outputfile
----------------
ANT_2
2433 2433 2 Jan 14 10:13:46 2009
Rule File Pathname: /home/la/_drc_
mt1 to gate area ratio > 40
p 1 44
-2109300 -10645700
-2095600 -10645700
-2095600 -10649700
-2088500 -10649700
-2088500 -10655700
-2071900 -10655700
ANT_6
1 1 2 Jan 14 10:14:01 2009
Rule File Pathname: /home/la/_drc_
gold diff gate inputs.

look at the "More UNIX and Linux Forum Topics You Might Find Helpful" box and see if there is a similar solution for you.

Ghostdog, Im not sure where the More Unix/Linux Forum is because I couldn't find it in this forum list.

I was able to get a code from this forum and apply it to what I'm doing. It's not exact but it's close.

code
-----

#!/bin/bash
function drcext
{
# Extract one line above and two lines below a pattern
awk '/[1-9] [1-9] /{ before-=1;after=2; next }
after { after--;next }
{ store[++before]=$0}
END {
for(i=1;i<=before;i++) {
print store
}
}' b > c
diff b c > d
sed -i 's/[0-9]*,[0-9]*[a-z]*[0-9]*/----------------------------------------------------------------/g' d
sed -i 's/< //g' d
# Add a variable content to the beginning of the file
rulepath=`grep Rule d`
sed -i '/Rule/d' d
sed "1i $rulepath" < d > e
}
drcext

This is my input file:

inputfile b
---------

die1 1000

WARN_1
0 0 2 May 4 16:20:21 2009 
Rule File Pathname: /coms
Rule File Pathname: /home/la/_tij4_drc_
TEOS_CH minimum spacing to VIA_1 is 10.0u, must not overlap
23_K
1 1 2 May 4 16:24:00 2009 
Rule File Pathname: /home/la/_tij4_drc_
TEOS_CH must be enclosed by Metal_3 10um min
p 1 4
CN tmplt c 1 0 0 1 0 0
-1512633 -8706882
-1507100 -8715212
-1507100 -8668836
-1512633 -8677166

Rule File Pathname: /home/la/_tij4_drc_
SU8_chm to Bond Pad min space is 10 um 
45_D2
20 20 2 May 4 16:30:03 2009 
Rule File Pathname: /home/la/_tij4_drc_
SU8_chm to Bond Pad at the end of a row min space is 100 um
e 1 2
CN die1 c 1 0 0 1 0 0
-1366000 -9000000 -1366000 -8991408
-1461658 -9029146 -1457396 -9031988
e 2 2
-1366000 -9000000 -1366000 -8981773
-1457396 -9031988 -1450898 -9034615
e 3 2
-1366000 -8804227 -1366000 -8800000

Rule File Pathname: /home/la/_tij4_drc_
Primer must be enclosed by SU8_prm
AT_1
2 2 2 May 4 16:30:20 2009 
Rule File Pathname: /home/la/_tij4_drc_
target must be covered by (drawn) dso
p 1 36
CN target_bondalign c 1 0 0 1 -1676600 7170000
-24000 0
-23635 -4168

Rule File Pathname: /home/la/_tij4_drc_
SU8_prm must overlap dso over gld_tgt by 3um min
AT_5
2 2 2 May 4 16:30:20 2009 
Rule File Pathname: /home/la/_tij4_drc_
SU8_prm/chm/nzl not allowed over gld_tgt
p 1 36
CN target_bondalign c 1 0 0 1 -1676600 7170000
-24000 0
-23635 -4168
-22553 -8208
-20785 -12000
-18385 -15427

Rule File Pathname: /home/la/_tij4_drc_
contact not allowed in stitch zone
su8_14_26A
55 55 2 May 4 16:30:30 2009 
Rule File Pathname: /home/la/_tij4_drc_
NOZZLE minimum width is 10um (for 14um thick material)
p 1 114
CN resistor_array c 1 0 0 1 0 0
-1052100 -7525307
-1052067 -7525796
-1052066 -7525803
-1051974 -7526268
 

This is my output file:

outputfile e
-----------

Rule File Pathname: /home/la/_tij4_drc_
----------------------------------------------------------------
23_K
1 1 2 May 4 16:24:00 2009 
TEOS_CH must be enclosed by Metal_3 10um min
----------------------------------------------------------------
AT_1
2 2 2 May 4 16:30:20 2009 
target must be covered by (drawn) dso
----------------------------------------------------------------
AT_5
2 2 2 May 4 16:30:20 2009 
SU8_prm/chm/nzl not allowed over gld_tgt
----------------------------------------------------------------
su8_14_26A
55 55 2 May 4 16:30:30 2009 
NOZZLE minimum width is 10um (for 14um thick material)
 

I'm not sure why the awk command delete the lines that are found by the search pattern [1-9] [1-9]. The originally posting for this code is for to extract the one line above and two lines below the pattern [1-9] [1-9]. This code is backward. It deletes instead of extract that's why I have to use the diff to get the lines that were delete. Please let me know how to recode it to extract instead of delete.

There is one problem with this code that I dont understand is that I use the pattern [1-9] [1-9] so it shouldn't be extracting the line:

55 55 2 May 4 16:30:30 2009

But that is what I wanted. I also want the line:

20 20 2 May 4 16:30:03 2009

But it didn't get extracted. How do I change the pattern /[1-9] [1-9] /, so that it will find any string; ie; 55 55 2 or 20 20 2? I've tried a different pattern /[1-9]* [1-9]* / or something along that line, but it's not working.

Sorry for the lengthy request but any advise would be greatly appreciated. This is my code:

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

Sorry about that, vgersh99. I'm new to Linux and this forum.

I just found and fix my codes. I changed the pattern to:

awk '/^[1-9]/{ before-=1;after=2; next }

But I'm still very interested to see if anyone has a better solution than this. I believe this can be done using a few lines.