bash - awk average in decimal -
i want write script gets average of 2 column of file first column equal, did awk. works, in output there exponential format data
121323e+2
changed print printf , added %f float
awk ' nr>1{ arr[$1] += $2 arr2[$1] += $3 count[$1] += 1 } end{ (a in arr) { printf "%4.3f", " " arr[a] / count[a] " " arr2[a] / count[a] } } ' t1.txt > t2.txt i have problem part:
printf "%4.3f", " " arr[a] / count[a] " " arr2[a] / count[a] - i want have enter after each printf line
- the spaces aren't exist in output
the output:
0001204.0001125.0001118.0001053.0001046.0001039.000901.000822.000815.000808.000750 which wanted
0001 204.000 1125.000 1118.000 1053.000 1046.000 1039.000 901.000 822.000 815.000 808.000 750
assuming rest of code want, should change printf this:
printf "%4.3f %4.3f %4.3f\n", a, arr[a] / count[a], arr2[a] / count[a] here i've included 1 format specifier each value inserted , added newline \n end. each value separated commas.
Comments
Post a Comment