Created
May 2, 2012 14:56
-
-
Save dmerand/2577179 to your computer and use it in GitHub Desktop.
Convert TSV file to HTML snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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