[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: How to convert logs to HTML including TABLES

From   Timothy P Cheney <>
Subject   Re: st: RE: How to convert logs to HTML including TABLES
Date   Wed, 29 Aug 2007 11:31:53 -0400 (EDT)

Thanks for the tip. I wrote a perl script that pretty much gets the job done. The major annoyance is that it won't get the header row right if there are embedded spaces in a column header. It could be smarter about it by looking ahead to an interior row of the table a figuring out the numerical column positions. It works with the text logs rather than the smcl. I would have liked to write something in stata but it would take forever to write using the limited macro string functions available.

$file1 = $ARGV[0];
$file2 = "$file1".".html";
open(FILE1,"<$file1") or die "Input file: Cannot open $file1\n\n";
open(FILE2,">$file2") or die "Output file: Cannot open $file2\n\n";

print FILE2 "<HTML><BODY>\n";


while (<FILE1>){
# if it is a command then print and return
if ($_ =~ /^[\.]/) { print FILE2 $_."<br>\n" }
# else if there is a pipe assume we are in a table
elsif ($_ =~ /[\|]/) {
if ($tab_on==0) {
print FILE2 "<TABLE BORDER=1>\n";
($stub, $rest)=split(/\|/,$_);
$rest =~ s/\s+/ /g;
#print "$rest\n";
@cells = split(/ /, $rest);
print FILE2 "<TR><TD>".$stub."</TD>";
foreach $cell (@cells) {
print FILE2 "<TD> $cell </TD>";
print FILE2 "</TR>\n";
# some tables have a "--------------+----------" which we will skip
elsif ($_ =~ /^[\-]+[\+][\-]+/) {
else {
if ($tab_on==1) {
print FILE2 "</TABLE>\n";
print FILE2 $_."<BR>\n";
else {

print FILE2 $_."<BR>\n";

print FILE2 "</BODY><HTML>/n";

print "$file2 created\n";

On Tue, 28 Aug 2007, Newson, Roger B wrote:

A possible route to automatic HTML table generation is to use
-xcontract- and -listtex-, both of which are downloadable from SSC.
-xcontract- creates an output Stata dataset (or resultsset) with 1
observation per combination of values and data on frequencies or
percents, -listtex- can convert such a dataset to a HTML table.

I hope this helps.


Roger Newson
Lecturer in Medical Statistics
Respiratory Epidemiology and Public Health Group
National Heart and Lung Institute
Imperial College London
Royal Brompton campus
Room 33, Emmanuel Kaye Building
1B Manresa Road
London SW3 6LR
Tel: +44 (0)20 7352 8121 ext 3381
Fax: +44 (0)20 7351 8322
Web page:
Departmental Web page:

Opinions expressed are those of the author, not of the institution.

-----Original Message-----
[] On Behalf Of Timothy P
Sent: 28 August 2007 18:25
Subject: st: How to convert logs to HTML including TABLES

Does anybody have a program to do this?  log2html creates html files but

does not parse the results into an HTML table.

When I produce a large number of tabs I would like to be able to dump
whole thing into a spreadsheet without having to copy as table and paste

each one.


*   For searches and help try:

*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index