Create a gist now

Instantly share code, notes, and snippets.

@jmhz /csv-2-JSON
Last active Dec 24, 2015

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