htmltable 0.1

htmltable is a configurable way to generate HTML tables from, for example, command output, ASCII text files, etc.

  Add it to your Download Basket!

 Add it to your Watch List!


Rate it!
send us
an update
GPL (GNU General Public License) 
Kevin Waldron
ROOT \ Internet \ HTTP (WWW)
htmltable is a configurable way to generate HTML tables from, for example, command output, ASCII text files, etc. The project requires that all input lines have equal numbers of fields. The first line of input is assumed to be a header line.


The configuration file for htmltable can take one of two forms, as defined by the "BGSTYLE" variable. A BGSTYLE of "ALT" would have each row with an alternating background colour, defined by the variables BGCOLOR1 and BGCOLOR2. If a BGSTYLE of "NORMAL" is defined, then use the BGCOLOR variable to set the background colour of all rows. Standard HTML colour values should be used. Other variables that are mandatory are CELLSPACING and BORDER. Optional HEADERCOLOR and TABLEBG values can also be defined. Sample configuration files are included in the tarball, and if enough interest in htmltable is shown I will get around to writing some decent documentation!


You'll need to set "BASEDIR" appropriately within the script (line 15).

The htmltable script has the following usage:

Usage: [-c ] [-d ] infile
-c - conf file - defaults to $BASEDIR/$CONFDIR/htmltable.conf
-d - delimiter - defaults to 't'

This script is designed to grab simple delimited plain text data and format as tabular HTML output

It can also be used to place command output in an HTML table, but requires more work and pre- processing, as each situation for command output is different...

kevin@foo ~/htmltable $ df -hP | tr -s ' ' | sed 's/Mounted on/Mounted on/' > in/
kevin@foo ~/htmltable $ ./bin/ -c ./conf/htmltable.conf -d' ' ./in/

As you can see, even for a simple df listing, we need to do a few things in order to get the listing in a parsable format.

First, we need to ensure that df outputs in -P (portability) mode, which ensures that each line isn't wrapped. Then, we use tr to -s (squeeze) the spaces.

Next, we use sed to replace "Mounted on" with "Mounted on" which ensures that we can use a space as our delimiter, whilst still displaying the space in the outputted HTML.

Other formats require different approaches, e.g.

kevin@foo ~/htmltable $ cat > /tmp/header
device mountpoint type options
kevin@foo ~/htmltable $ mount | sed -e 's/ on//' -e ' s/ type//' | cat /tmp/header - >
kevin@foo ~/htmltable $ ./bin/ -c ./conf/htmltable.conf -d' ' ./in/

We can then test this....

kevin@foo ~/htmltable $ ( echo ""
> ./bin/ -c ./conf/htmltable.conf -d' ' ./in/
> echo "" ) /tmp/infile.html

Then browse /tmp/infile.html

Last updated on March 12th, 2007

#generate HTML tables #ASCII text #HTML tables #htmltable #generate #HTML #tables

Add your review!