#!/usr/bin/awk -f # Copyright 2000 Blossom Associates West # All rights reserved. # Makes an HTML table out of a table of tab separated values. # This version will pass through unchanged lines that do not contain tabs. # Note that there can be multiple separate tables in such a file. # This can help when composing HTML that contains tables. # The tables can be composed with tabs, # Then the result can be run through this to convert to markup. # Another fun one is to use FS=" *| *" for composing. BEGIN { FALSE = 0; TRUE = ! FALSE; FS = "\t"; OFS = ""; inTable = FALSE; } $0 ~ FS { # Maybe could use 1 < NF instead? if ( ! inTable ) { print ""; inTable = TRUE; } $1 = $1; # Replace field separators. print ""; next; } { if ( inTable ) { printf "
" $0 "
\n"; inTable = FALSE; } print; } END { if ( inTable ) { printf "\n"; inTable = FALSE; } }