Skip to content

Instantly share code, notes, and snippets.

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

What would you like to do?
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
print "var dataset = {";
print "\t\""$1"\": [";
for (i=2;i<NF;i++) {
printf(" % +3.6f, ",$i);
printf(" % +3.6f ",$NF);
print " ] ,";
print " }";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.