#!/usr/bin/awk -f # Converts from a rdbtable text table to HTML. # There may be zero or more comment lines before the headings. # Next comes a single line of headings. # Each column heading must be exactly one word. # Then come the data lines, i.e. the rows. # Eric Blossom - January 2002 # see http://www.cse.ucsc.edu/research/compbio/rdb/rdbtable.html # Only the justification (left or right) is used from the column format line. # e.g. # # First comment # one two three # column names # 12 1S> 6N # column formats # 1 2 3 # data # 4 x 6 # data BEGIN { FS = "\t"; firstComment = 0; titleLine = 1; fmtLine = 2; colAlignment[1] = ""; colComment[1] = ""; } /^(# )|( *#)/ && 0 == firstComment { firstComment = NR; print "
";
}

/^(# )|(  *#)/ {
  match( $0, "^(# )|(  *#)" );
  print substr( $0, RLENGTH+1 );
  titleLine++;
  fmtLine++;
  next;
}


titleLine == NR {
  if ( 0 < firstComment ) {
    print "
"; } print ""; print ""; for ( i = 1; i <= NF; i++ ) { printf( "", $i ); } print ""; next; } fmtLine == NR { for ( i = 1; i <= NF; i++ ) { frmt = $i; n = index( $i, " " ); if ( 0 < n ) { frmt = substr( $i, 0, n-1 ); colComment[i] = substr( $i, n+1 ); } n = match( $i, "[N>]" ); if ( 0 < n ) { colAlignment[i] = "right"; } } next; } { print ""; for ( i = 1; i <= NF; i++ ) { tagAttributes = ""; if ( colAlignment[i] ) { tagAttributes = tagAttributes " align=\"" colAlignment[i] "\""; } if ( colComments[i] ) { } printf( "%s", tagAttributes, $i ); } print ""; } END { print "
%s
"; }