awk to create two HTML Tables

I am working on awk script to generate an HTML format output. With input file as below I am able to generate a HTML file however I want to saperate spare devices in a different table than rest of the devices and which has only Bunch ID, RAW Size and "Bunch Spare" status columns.

INPUT File :

Bunch ID                              0
Bunch Type:                            ATTR5
RCAP:                     751625160
LCAP:                 601300096
FREE CAP: 1024

Bunch ID                              10
Bunch Type:                            ATTR5
RCAP:                     4221283480
LCAP:                 3377026688
FREE CAP: 42554880

Bunch ID                              201
Bunch Spare:            16
Bunch Type:                            spare
RCAP:                     280278760
LCAP:                 280278656
FREE CAP: 0

Bunch ID                              202
Bunch Spare:            Inactive
Bunch Type:                            spare
RCAP:                     280278760
LCAP:                 280278656
FREE CAP: 0

Bunch ID                              300
Bunch Type:                            ATTR10
RCAP:                     698409370
LCAP:                 558727424
FREE CAP: 0

Bunch ID                              458
Bunch Spare:            Inactive
Bunch Type:                            spare
RCAP:                     1923401229
LCAP:                 1923401216
FREE CAP: 0

Bunch ID                              459
Bunch Spare:            Inactive
Bunch Type:                            spare
RCAP:                     844256696
LCAP:                 844256640
FREE CAP: 0

#!/bin/ksh -x
HOST_IP=192.168.23.99
HDCLI=/opt/HDS/bin/hdcli
SUDO=/usr/bin/sudo
GAWK=/bin/awk
TMPFILE=/tmp/GRP_tmp
OUTFILE=/tmp/GRP_out
FILE_Y=/tmp/HD_el_sts_Yellow.$$
R_FILE=/tmp/HD_el_sts_Red.$$
LCAP_LST=/tmp/logical_cap.$$
GRPFREE_CAP=/tmp/GRP_freeSize.$$

        $SUDO $HDCLI -h $HOST_IP grp -type -catp > $TMPFILE # This command produces output exact as in INPUT FILE

   cat $TMPFILE | $GAWK -v YFILE=$FILE_Y -v RFILE=$R_FILE '
        BEGIN {
                FLAG=0
                hot_spares=0
                REDLINE=""
                YELLOWLINE=""
                spacer="   "
                print "<table width=\"100%\" border=0><tbody><tr><th align=center><font size=+1><b>Array Size Report</b></font></th></tr>"
                print "<table width=\"100%\" border=\"1\">\n<tbody><tr><th align=\"center\">GRP-Bunch ID</th><th align=\"center\">GRP Type</th><th align=\"center\">RAW Size</th><th align=\"center\">Usable Size</th><th align=\"center\">Free Size</th></tr>"
        }
        {

                if (($0 ~ /Bunch ID/) || ($0 ~ /Bunch Type/) || ($0 ~ /RCAP/) || ($0 ~ /LCAP/) || ($0 ~ /FREE/)) {
                        split($0, blocks, ": *")

                        if (blocks[1] ~ /Bunch ID/) {
                                GRPID=blocks[2]
                        printf("<td align=\"left\">%s</td>\n",  GRPID)
                        }


                        if (blocks[1] ~ /Bunch Type/) {
                        GRPTYPE=blocks[2]
                        printf("<td align=\"left\">%s</td>\n",  GRPTYPE)
                        }
                        if (blocks[1] ~ /RCAP/) {
                                GRPRAW=blocks[2]
                                GRPRAWGB=((((GRPRAW*512)/1024)/1024)/1024)
                        #       GRPRAWGBD= sprintf("%4.4f", GRPRAWGB)
                        printf("<td align=\"left\">%s</td>\n",  GRPRAWGB)
                        }
                        if (blocks[1] ~ /LCAP/) {
                                GRPLGCL=blocks[2]
                                GRPLGCLGB=((((GRPLGCL*512)/1024)/1024)/1024)
                        printf("<td align=\"left\">%s</td>\n",  GRPLGCLGB)
                        }

                        if (blocks[1] ~ /FREE/) {
                                GRPCONT=blocks[2]
                                GRPCONTGB=((((GRPCONT*512)/1024)/1024)/1024)
                                GRPCONTGBD= sprintf("%7.3f", GRPCONTGB)
                        printf("<td align=\"left\">%s</td></tr>\n",  GRPCONTGBD)
                        }

                }

        }

        END {
                print "</tr></tbody></table></td></tr></tbody></table>"

                }' > $OUTFILE

OUTPUT FILE: I have come thus far however would like to split table so that can sort Spare devices at the bottom.

Array Capacity Report Bunch ID GRP Type RAW Size Usable Size Free Size199
ATTR1 805.146 402.573 2.573 200 ATTR10 1610.29 805.146 305.146 201 spare 133.647 133.647 0.000 202 spare 133.647 133.647 0.000 203 spare 133.647 133.647 0.000 300 ATTR5 333.028 266.422 0.000 302 ATTR10 3220.58 1610.29 1110.292 303 ATTR10 3220.58 1610.29 1275.000461 spare
917.149 917.1490.000 204 spare 133.647 133.647 0.000

---------- Post updated at 01:50 PM ---------- Previous update was at 01:36 PM ----------

Here is picture of current o/p.

This is how I would like to have it.
Bunch ID
GRP Type
RAW Size
Usable Size
Free Size
199
ATTR1
805.146
402.573
2.573
200
ATTR10
1610.29
805.146
305.146
300
ATTR5
333.028
266.422
1110.292
302
ATTR10
3220.58
1610.29
1275.000

Spare Status Report
Bunch ID
RAW Size
Bunch Spare

         201
     133.647
     16
         202
     133.647
     Inactive
         458
     917.149
     Inactive

Here is pic of what I am expecting

Basically, accumulate in the main loop and write in END{} function.

This is standard in HTML to avoid multiple passes on the data.

I've not gone into details of the exact script, but it should be straight forward.

In BEGIN{}, assign the two table's header to strings thus:
strA="<table width=\"100%\" border=0><tbody><tr><th align=center><font size=+1><b>Array Size Report</b></font></th></tr>"
strB="<table width=\"100%\" border=\"1\">\n<tbody><tr><th align=\"center\">GRP-
Bunch ID</th><th align=\"center\">GRP Type</th><th align=\"center\">RAW Size</th>
<th align=\"center\">Usable Size</th><th align=\"center\">Free Size</th></tr>"

In main {}
if free strB+=<data> else strA+=<data>

On END{}
and so on.