find 2 line numbers, grab text in between

hi, i have a large text file that I just want to extract the important
information from. It will be a random number of lines but between two specific
line numbers/markers.

I was thinking I could get the line number for the first marker:
Tablespace Percent Total Free

Then get the line number for the second marker:
Tablespace Free Space Avg Fragmentation

Now all I would need to do is print out the text between the two lines
(including the 1st marker but not the second):
print 1st_marker_line# --> 2nd_marker_line#

I am pretty sure I can do this with awk but not sure how.
Thanks for your help!

Sample text:

09/25/06      SPCCHK - Tablespace Percent Total Free Values on SWB
                                                                   %chg Days
Tablespace                                                  Today since till
   Name           09/18 09/19 09/20 09/21 09/22 09/23 09/24 09/25  yest zero
----------------- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
BDR_DATA           89.5  89.5  89.4  89.4  89.4  89.3  89.3  89.1   -.2
SYSAUX             71.0  70.5  70.0  71.5  71.1  70.6  70.0  71.4   1.4
SYSTEM             22.7  22.7  22.7  22.7  22.7  22.6  22.2  22.2    .0  297
UNDOTBS1           21.8  21.8  22.5  31.0  30.8  29.8  29.9  30.9   1.0

09/25/06  SPCCHK - Tablespace Free Space Avg Fragmentation Pct on SWB

Fragmentation Pct is calculated by dividing the number of data files for a
 tablespace by the number of different chunks of free space within those 
data files.  The lower the number, the more fragmented your free space is.

                                                                   %chg
Tablespace                                                  Today since
   Name           09/18 09/19 09/20 09/21 09/22 09/23 09/24 09/25  yest
----------------- ----- ----- ----- ----- ----- ----- ----- ----- -----
SYSAUX             16.7  20.0  16.7    .5    .6    .8   2.3   1.0  -1.3
UNDOTBS1             .3    .3    .3    .2    .2    .2    .3    .3    .0

etc. etc. etc.

this is all I want printed out (or sent to to a file or whatever):

09/25/06      SPCCHK - Tablespace Percent Total Free Values on SWB
                                                                   %chg Days
Tablespace                                                  Today since till
   Name           09/18 09/19 09/20 09/21 09/22 09/23 09/24 09/25  yest zero
----------------- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
BDR_DATA           89.5  89.5  89.4  89.4  89.4  89.3  89.3  89.1   -.2
SYSAUX             71.0  70.5  70.0  71.5  71.1  70.6  70.0  71.4   1.4
SYSTEM             22.7  22.7  22.7  22.7  22.7  22.6  22.2  22.2    .0  297
UNDOTBS1           21.8  21.8  22.5  31.0  30.8  29.8  29.9  30.9   1.0

Perhaps this is what you want:

#!/bin/bash

TOK1="SPCCHK - Tablespace Percent Total Free Values"
TOK2="SPCCHK - Tablespace Free Space Avg Fragmentation"

INTERESTING=no
while read l; do
   TXT1=$(echo $l | grep "$TOK1")
   TXT2=$(echo $l | grep "$TOK2")
   if [[ "$TXT1" != "" ]]; then
      INTERESTING=yes
   elif [[ "$TXT2" != "" ]]; then
      INTERESTING=no
   fi
   if [[ "$INTERESTING" == "yes" ]]; then
      echo "$l"
   fi
done < ./input_file.txt

Script for bash, and probably for ksh. Needs that "./input_file.txt" exists.

Regards.

sed -n "/Tablespace Percent Total Free/,/Tablespace Free Space Avg Fragmentation/ p" file | sed "$ d" 

something to start with:

nawk -v pat='Tablespace Percent Total Free' -f duck.awk myReportFile.txt

duck.awk:

BEGIN {
   RS=FS=""
}
$1 ~ pat
sed -n "/Tablespace Percent Total Free/,/Tablespace Free Space Avg Fragmentation/{ /Tablespace Free Space Avg Fragmentation/!p; }" file

thanks for the quick responses.

Also, what if there is more than one block (same rules) within the same filename that I need to extract?
So there would be 2-3 sets of markers possibly.

If you have same kind of markers then you will get all those blocks

I just tested this. very nice!
there is only one extra line that I don't need, but it is not a big deal.

sed -n "/Tablespace Percent Total Free/,/Tablespace Free Space Avg Fragmentation/ p" /export/home/oracle/dba/spcchk.lis | sed "$ d"
09/25/06      SPCCHK - Tablespace Percent Total Free Values on BAT
                                                                   %chg Days
Tablespace                                                  Today since till
   Name           09/18 09/19 09/20 09/21 09/22 09/23 09/24 09/25  yest zero
----------------- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
FILE_NDX           25.6  25.5  25.5  25.5  25.4  25.4  25.3  25.3    .0
SYSAUX             40.3  43.0  42.2  41.2  40.3  42.8  42.1  41.2   -.9
SYSTEM             61.4  61.2  61.2  61.2  61.1  61.1  61.1  61.1    .0
UNDOTBS1           81.4  81.0  81.2  80.8  81.0  80.8  81.0  81.2    .2
USERS              87.1  87.1  87.1  87.1  86.6  86.6  86.6  86.6    .0

## don't need "Fragmentation" line below -- I could just grep -v it out however
09/25/06  SPCCHK - Tablespace Free Space Avg Fragmentation Pct on BAT
09/25/06     SPCCHK - Tablespace Percent Total Free Values on CCST
                                                                   %chg Days
Tablespace                                                  Today since till
   Name           09/18 09/19 09/20 09/21 09/22 09/23 09/24 09/25  yest zero
----------------- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
ACTIVE_SEATS       14.1  14.1  14.1  12.5  12.5  12.5  12.5  12.5    .0   42
ACTIVE_SEATS_NDX   43.7  43.7  43.7  43.7  43.7  42.2  42.2  42.2    .0  158
ATTEMPTS           25.0  24.2  24.2  24.2  24.2  24.2  24.2  24.2    .0  361
ATTEMPTS_NDX       86.0  86.0  86.0  86.0  86.0  85.9  85.9  85.9    .0
GEN_NDX            48.8  48.8  48.8  48.8  48.8  48.8  48.8  48.6   -.2
SYSAUX             44.0  46.7  45.8  45.1  44.1  46.7  45.8  45.1   -.7
SYSTEM             44.2  44.2  44.2  44.2  44.2  44.0  44.0  44.0    .0
UNDOTBS            85.1  84.8  84.9  84.6  84.2  84.1  84.5  85.2    .7

use this . u wont get unwanted line

sed -n "/Tablespace Percent Total Free/,/Tablespace Free Space Avg Fragmentation/{ /Tablespace Free Space Avg Fragmentation/!p; }" file

that second script is not working. For some reason it is converting the "!" to something weird.

graham_ccst> sed -n "/Tablespace Percent Total Free/,/Tablespace Free Space Avg Fragmentation/ \
> { /Tablespace Free Space Avg Fragmentation/!p; }" /export/home/oracle/dba/spcchk.lis
{ /Tablespace Free Space Avg Fragmentation/p[wd; }" /export/home/oracle/dba/spcchk.lis
sed: command garbled: /Tablespace Percent Total Free/,/Tablespace Free Space Avg Fragmentation/ { /Tablespace Free Space Avg Fragmentation/p[wd; }

try this

sed -n -f sed_spt file

sed_spt
#############################
/Tablespace Percent Total Free/,/Tablespace Free Space Avg Fragmentation/{ 
/Tablespace Free Space Avg Fragmentation/!p; 
}
#############################

nice! You DA MAN. This is perfect.
Thanks very much.

> sed -n -f sed_spt /export/home/oracle/dba/spcchk.lis
09/25/06      SPCCHK - Tablespace Percent Total Free Values on BAT
                                                                   %chg Days
Tablespace                                                  Today since till
   Name           09/18 09/19 09/20 09/21 09/22 09/23 09/24 09/25  yest zero
----------------- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
FILE_NDX           25.6  25.5  25.5  25.5  25.4  25.4  25.3  25.3    .0
SYSAUX             40.3  43.0  42.2  41.2  40.3  42.8  42.1  41.2   -.9
SYSTEM             61.4  61.2  61.2  61.2  61.1  61.1  61.1  61.1    .0
UNDOTBS1           81.4  81.0  81.2  80.8  81.0  80.8  81.0  81.2    .2
USERS              87.1  87.1  87.1  87.1  86.6  86.6  86.6  86.6    .0

09/25/06     SPCCHK - Tablespace Percent Total Free Values on CCST
                                                                   %chg Days
Tablespace                                                  Today since till
   Name           09/18 09/19 09/20 09/21 09/22 09/23 09/24 09/25  yest zero
----------------- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
ACTIVE_SEATS       14.1  14.1  14.1  12.5  12.5  12.5  12.5  12.5    .0   42
ACTIVE_SEATS_NDX   43.7  43.7  43.7  43.7  43.7  42.2  42.2  42.2    .0  158
ATTEMPTS           25.0  24.2  24.2  24.2  24.2  24.2  24.2  24.2    .0  361
ATTEMPTS_NDX       86.0  86.0  86.0  86.0  86.0  85.9  85.9  85.9    .0
GEN_NDX            48.8  48.8  48.8  48.8  48.8  48.8  48.8  48.6   -.2
SYSAUX             44.0  46.7  45.8  45.1  44.1  46.7  45.8  45.1   -.7
SYSTEM             44.2  44.2  44.2  44.2  44.2  44.0  44.0  44.0    .0
UNDOTBS            85.1  84.8  84.9  84.6  84.2  84.1  84.5  85.2    .7