Hi scottn, yes you're right, its not an awk error. I'm using this statement in a ksh script on solaris...
I'm basically trying to send in a .csv file full of numbers and N/A's and getting the sum appended to it..
awk -F"," '{for (i=1;i<=NF ; ++i) { if($i !~ /N\/A/) {sum += $i;}} if (i > max) max=i }
END { s=""; for (i=1; i<=max; ++i) { printf "%s%s", s, sum; s=",";} printf "\n" }' format.csv > ffname
cat format.csv
format.csv is something like this
20100803,N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, ,
20100804, 183, 234, 29, 31, 0, 0, 0, 0, 25, 127, 6, 21, 285, 49, 0, 0, 0, 0, 217, 2, 27, 0, 968, 332,
20100802,N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, ,
20100803,N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, N/A, ,
I'm adding the columns corresponding to the dates...
so my result should be :-
183, 234, 29, 31, 0, 0, 0, 0, 25, 127, 6, 21, 285, 49, 0, 0, 0, 0, 217, 2, 27, 0, 968, 332,
I'm getting the result but with this error on the console, which i don't want...
finale4[71]: N/A,: unknown test operator
---------- Post updated at 09:43 PM ---------- Previous update was at 09:40 PM ----------
@methyl : - sum [i]is the array that holds my column sum...