Skip to content

Instantly share code, notes, and snippets.

@dmerand
Created May 2, 2012 14:56
Show Gist options
  • Save dmerand/2577179 to your computer and use it in GitHub Desktop.
Save dmerand/2577179 to your computer and use it in GitHub Desktop.
Convert TSV file to HTML snippet
#!/bin/sh
#convert a TSV file to an HTML file
#author: Donald L. Merand
#note: this is most useful in conjunction with bcat, which sends results to the browser
# you can get bcat on OS X using homebrew
# http://mxcl.github.com/homebrew/
# then type "brew install bcat"
#also note: this script only creates an HTML snippet - you'll probably want to wrap
# it in some pretty CSS, not to mention <html> and <body> tags
#convert Mac line endings, if any
perl -p -e 's/\r/\n/g' |
#now do the conversion
awk '
BEGIN {
FS="\t"
printf "<table>\n"
}
{
printf "\n\n<tr>"
for (i=1;i<=NF;i++) {
printf "<td>%s</td>", $i
}
printf "</tr>"
}
END {
printf "\n</table>"
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment