Skip to content

Instantly share code, notes, and snippets.

@jmhz
jmhz / csv-2-JSON
Last active December 24, 2015 21:49
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"\": [";
@jmhz
jmhz / min-max.awk
Last active December 24, 2015 18:09
An Awk Script to find the min max of each field and overall. Invoked with cat vectors.txt | awk -F\ -f min-max.awk
BEGIN {
for (i=2;i<=NF;i++) { # first field is ignored i starts from 2
min[i] = 9.999999;
max[i] = -9.999999;
};
}
{
for (i=2;i<=NF;i++) { # first field is ignored i starts from 2
if ($2<min[i]) { min[i]=$i; };
if ($2>max[i]) { max[i]=$i; };