awk to create two HTML Tables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk to create two HTML Tables
# 1  
Old 07-08-2011
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 :
Code:
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

Code:
#!/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
# 2  
Old 07-08-2011
Here is pic of what I am expecting

Here is pic of what I am expecting
awk to create two HTML Tables-junk0jpg
# 3  
Old 07-08-2011
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extract the tables from html

Hi I have a script which extracts the table from HTML and convert it into .csv. But the problem in the script is if we have 2 tables in HTMl . it takes only the first table. Please help me what changes i need to do in the script to make it read the complete HTML page. Script is as below: ... (10 Replies)
Discussion started by: deepti01
10 Replies

2. HP-UX

Unable to send attachment with html tables in UNIX shell script

Heyy, any help would be grateful.... LOOKING FOR THE WAYS TO SEND AN EMAIL WITH ATTACHMENT & HTML TABLES IN BODY THROUGH SHELL SCRIPT (LINUX)..NOT SURE, IF WE HAVE ANY INBUILT HTML TAG OR UNIX COMMAND TO SEND THE ATTACHMENTS. KINDLY HELP below is small script posted for our understanding..... (2 Replies)
Discussion started by: Harsha Vardhan
2 Replies

3. Shell Programming and Scripting

Splitting csv into 3 tables in html file

I have the data in csv in 3 tables. how can I output the same into 3 tables in html.also how can I set the width. tried multiple options . attached is the format. #!/bin/ksh awk 'BEGIN{ FS="," print "<HTML><BODY><TABLE border = '1' cellpadding=10 width=100>" print... (7 Replies)
Discussion started by: archana25
7 Replies

4. UNIX for Dummies Questions & Answers

Help me to create html document

Hi all, I have to find the count from File. tsv and need the output file format will be in html using shell script. Ex: File.tsv A B C D 1 2 3 4 5 6 7 4 9 10 11 12 output in html: FileName Count A 3 (1 Reply)
Discussion started by: Shenbaga.d
1 Replies

5. Programming

MySQL: Create a relation between two tables.

Hello everybody, I'm having troubles creating a relation between two tables in a MySQL database. Having two tables, being one which contains users information (username, password, user ID, etc) and the other the one which contains transactions information (operation type, user ID of the user who... (2 Replies)
Discussion started by: semash!
2 Replies

6. Shell Programming and Scripting

help with a bash script to create a html table

Hi guys as the title says i need a little help i have partisally written a bash script to create a table in html so if i use ./test 3,3 i get the following output for the third arguement in the script i wish to include content that will be replace the A characters in the... (2 Replies)
Discussion started by: dunryc
2 Replies

7. Shell Programming and Scripting

Create a html file if a process is running??

Hi All, I need to check for a process, if the process is running then I have to create an HTML file, say A.HTML. If the process is not running then I have to rename the existing html, say A.HTML to B.HTML so that the process which looks for the file A.HTML does not find it? How do I do... (1 Reply)
Discussion started by: Hangman2
1 Replies

8. UNIX and Linux Applications

create 'day' tables based on timestamp in mysql

How would one go about creating 'day' tables based on the timestamp field. I have some 'import' tables which contains data from various days and would like to spilt that data up into 'days' based on the timestamp field in new tables. TABLE_IMPORT1 TABLE_IMPORT2 TABLE_IMPORT3 ... (2 Replies)
Discussion started by: hazno
2 Replies

9. UNIX for Dummies Questions & Answers

extract data from html tables

hi i need to use unix to extract data from several rows of a table coded in html. I know that rows within a table have the tags <tr> </tr> and so i thought that my first step should be to to delete all of the other html code which is not contained within these tags. i could then use this method... (8 Replies)
Discussion started by: Streetrcr
8 Replies

10. Shell Programming and Scripting

Converting tables of row data into columns of tables

I am trying to transpose tables listed in the format into format. Any help would be greatly appreciated. Input: test_data_1 1 2 90% 4 3 91% 5 4 90% 6 5 90% 9 6 90% test_data_2 3 5 92% 5 4 92% 7 3 93% 9 2 92% 1 1 92% ... Output:... (7 Replies)
Discussion started by: justthisguy
7 Replies
Login or Register to Ask a Question