Formatting output table

I have an issue with formatting my output table. It is not correctly formatted

BEGIN{
   width=70
   qq="\""
   numSuf="^[0-9.]+[MGT%]?$"
   printf("<table border=1 width=%s%c cellspacing=0 cellpadding=0 align=left>", width, "%")
}
FNR==1{NF--}
{
   print "<tr>"
   for(i=1;i<=NF;i++)
     printf("<td style=%stext-align:%s;%s> %s </td>\n", qq, ($i~numSuf)?"right":"left", qq,$i)
   print "<tr>"
}
END {
   print "</table>"
}

and this is my output

Even after increasing my table width the first row is still messed up. Could anyone help me figure out why is it like that?

Hi,

  • What does your input look like?
  • Is that df -h output?
  • What is your OS and platform?
  • my input looks like this
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_ol6112rac1-lv_root
                       26G   23G  1.7G  94% /
tmpfs                 2.0G  1.2G  835M  58% /dev/shm
/dev/sda1             477M   64M  384M  15% /boot
/dev/sr0               83M   83M     0 100% /media/VBox_GAs_6.0.6
windows10             932G  426G  506G  46% /media/sf_windows10

  • yes its the df -h output

  • im using oracle 11gR2 running on oracle linux 6

Hi @batmanstan

You need to use the colspan attribute to get your table to format correctly.

See:

https://www.w3schools.com/tags/att_colspan.asp

2 Likes

Another thing you could check is the following df options:

'-P'
'--portability'
     Use the POSIX output format.  This is like the default format
     except for the following:

       1. The information about each file system is always printed on
          exactly one line; a mount device is never put on a line by
          itself.  This means that if the mount device name is more than
          20 characters long (e.g., for some network mounts), the
          columns are misaligned.
1 Like

thanks you that works, dont mind i have another problem. It is to display my asm votedisk in a table, are there options for that also?

##  STATE    File Universal Id                File Name Disk group
--  -----    -----------------                --------- ---------
 1. ONLINE   ae971fc838f54fc1bfd426c8497afd38 (/dev/asm-disk1) [DATA]
Located 1 voting disk(s).

this should be somewhat similar to the scripting for df -h provided previously - definitely not the same, but the concepts should be the same.
I believe the output is from running crsctl query css votedisk mentioned here.
Where this command has a similar -P option as the df does, it should be in the manual (if that is your question).
Could you post a "the similar script as above", please.
What is "broken"?
P.S. just ran your awk script against your NEW sample data - it looks like it creates the html file that the browser displays exactly like you quoted above.
What's broken?

i dont think the script is broken, its just that format the output to fit the table nicely. The table includes the "--------" and "located 1 voting disk", just wondering is there a way to not include those two.

sure, just change the script to skip these 2 patterns when processing records/lines.
Give it a whirl and see how far it gets you.

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.