sh script that reads/writes based upon contents of a file

Hi everyone,

Ive got a quick question about the feasibility and any suggestions for a shell script. I can use sh or ksh, doesnt matter. Basically, Ive got an output file from a db2 command that looks like so:

SCHEMA NAME CARD LEAF ELEAF LVLS ISIZE NDEL KEYS F4 F5 F6 F7 F8 REORG
-------------------------------------------------------------------------------------------------
Table: DB2INST2.ADVISE_INDEX
DB2INST2 IDX_I1 4 1 0 1 10 0 2 100 - - 0 0 -----
DB2INST2 IDX_I2 4 1 0 1 24 0 4 100 - - 0 0 -----
Table: DB2INST2.ADVISE_INSTANCE
SYSIBM SQL060710185042710 2 1 0 1 10 0 2 100 - - 0 0 -----
Table: DB2INST2.ADVISE_MQT
DB2INST2 MQT_I1 - - - - - - - - - - - - -----
DB2INST2 MQT_I2 - - - - - - - - - - - - -----
Table: DB2INST2.ADVISE_PARTITION
DB2INST2 PRT_I1 - - - - - - - - - - - - -----
Table: DB2INST2.Active_Server_Pages
DB2INST2 ACTSRVPG_IDX - - - - - - - - - - - - -----
Table: DB2INST2.Active_Server_Pages_D
DB2INST2 ACTSRVPG_DX 8622 127 0 3 97 0 8622 65 89 52 0 0 *----
DB2INST2 ACTSRVPG_DX2 8622 41 0 2 82 0 2889 76 90 2 0 0 *----
Table: DB2INST2.Active_Server_Pages_H
DB2INST2 ACTSRVPG_HX 20492 302 0 3 97 0 20492 7 89 22 0 0 *----

If any of you are db2 dba's, youll recognize its the output for reorgchk. Basically what im trying to do is to move the string after "Table: " to a differnt file if any of the output between it and the next occurance of "Table: " contains a star(*). Im thinking I would need to use SED to somehow extract that block of text, put it in another file, place the schema.tablename (in the last case it is DB2INST2.Active_Server_Pages_H) in a variable, grep that file for the star, and if it exists (no matter how many occurances), then write that variable that has the schema.tablename to another file enclosed in a command that I already have (will be reorg table). Any takers on the feasibility of this? Please request clarification if nessesary.

try

#!/bin/ksh

awk 'BEGIN {i=-1}
{
 if($1 ~ /^Table/) { i++;}
 arr=arr "\n" $0;   
}
 END { for (i in arr) { if(index(arr,"*")>0) {print arr;} } }
 	 
 ' filename

awk '/^Table/{table=$0; f=1 } /\*/ { if (f--) { print table }}'

THANKS both of you guys! One minor adjustment I made though...specifically I need just the table name out of the line, not the entire line, so I used $2 to print to the file instead of $0...Thanks though!