Skip to content

Instantly share code, notes, and snippets.

@jmhz
Last active December 24, 2015 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmhz/6867910 to your computer and use it in GitHub Desktop.
Save jmhz/6867910 to your computer and use it in GitHub Desktop.
CSV to Javascript array in awk
# awk CSV to JS Array js file
# cat vectors.csv | awk -F\ -f jmhz-csv-to-js-array-awk.awk > vector_array.js
# in this case the 1st field is the name and is used as the index
# License : GPL v3
BEGIN{
print "var dataset = {";
}
{
print "\t\""$1"\": [";
for (i=2;i<NF;i++) {
printf(" % +3.6f, ",$i);
}
printf(" % +3.6f ",$NF);
print " ] ,";
}
END{
print " }";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment