#!/usr/bin/awk -f # Copyright 2001 Blossom Associates West # All rights reserved. # The first file is an HTML template with a table in it. # Subsequent files contain the data. Typically TSV. # The table can have lines like "%s" in it # which will be filled in with fields in the TSV. # The "" lines of the form above must be enclosed in tr tagged lines. # e.g. # %d: # %s # # Note that each td tag must be on a separate line. # There must be only one such stanza in the template. BEGIN { FALSE = 0; TRUE = ! FALSE; startTag = /< *[Bb][Oo][Dd][Yy]/; endTag = />/; printing = FALSE; tempSize = 0; DFLTFMT = "%s"; } 1 == FNR && 1 < NR { inData = TRUE; } inData { print rowHeader; for ( i = 1; i <= NF; i++ ) { if ( i <= tempSize ) { fmt = templ[i]; } else { fmt = DFLTFMT; } printf( fmt, $i ); } print rowTrailer; next; } /%[-sd1-9].*<\/td/ && length( rowTrailer ) < 1 { tempSize++; templ[ tempSize ] = $0; next; } /<\/tr/ && 0 < tempSize { rowTrailer = $0; } 0 < length( rowHeader ) { if ( tempSize < 1 ) { print rowHeader; rowHeader = ""; } } /