Skip to content

Instantly share code, notes, and snippets.

@TooDumbForAName
Last active June 8, 2017 11:36
Show Gist options
  • Save TooDumbForAName/8bb45e115a0ccf9d3fb1fcf86bca181d to your computer and use it in GitHub Desktop.
Save TooDumbForAName/8bb45e115a0ccf9d3fb1fcf86bca181d to your computer and use it in GitHub Desktop.
Basic CSV to HTML converter
#!/bin/bash
FILENAME=$1
if [ "$FILENAME" == "" ];
then
printf "%s\n" "Please specify the name of the CSV file to convert:"
read FILENAME
fi
IFILE=$FILENAME.copy
cp $FILENAME $IFILE
sed -i 's|,|</TH><TH>|g' $IFILE
sed -i 's|^|<TR><TH>|g' $IFILE
sed -i 's|$|</TH></TR>|g' $IFILE
#begin basic HTML document
touch header.html
printf "%s\n" "<HTML>" >> header.html
printf "%s\n" "<HEAD>" >> header.html
printf "%s\n" "<TITLE></TITLE>" >> header.html
printf "%s\n" "</HEAD>" >> header.html
printf "%s\n" "<BODY>" >> header.html
printf "%s\n" "<TABLE>" >> header.html
cat header.html $IFILE > csv.html
rm $IFILE
rm header.html
printf "\n%s\n" "</TABLE>" >> csv.html
printf "%s\n" "</BODY>" >> csv.html
printf "%s\n" "</HTML>" >> csv.html
@TooDumbForAName
Copy link
Author

TooDumbForAName commented Jun 8, 2017

I wrote this in like 10 minutes as an example for someone on Yahoo Answers. It's obviously terrible in several ways, but if you want it, you can have it. I have no use for such a thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment