Try:
awk -F, -v sq="'" '
{ printf("record %s sum is %" sq ".2f\n", $1, $2 / 100)
r[NR] = $1
c[NR] = $3
}
END { for(i = 1; i <= NR; i++) printf("record %s count is %s\n", r, c)
}' file
which, with an input file containing:
345,12,10
400,11,8
328,1,3
111,1234567890,9
produces the output:
record 345 sum is 0.12
record 400 sum is 0.11
record 328 sum is 0.01
record 111 sum is 12,345,678.90
record 345 count is 10
record 400 count is 8
record 328 count is 3
record 111 count is 9
Alternatively, you could do it with externally defined complete format strings as in:
awk -F, '
{ printf(sum_format, $1, $2 / 100)
r[NR] = $1
c[NR] = $3
}
END { for(i = 1; i <= NR; i++) printf(count_format, r, c)
}' sum_format="record %s sum is %'.2f\n" count_format="record %s count is %s\n" file
which produces the same output as the previous script.
This isn't the format you showed in your latest request (since you did not show a decimal point nor did you show two digits following the decimal point), but should do what you were trying to do with the format string %'.2f
(assuming that the field 2 value in your input is a number of pennies rather than a number of dollars).
In the future PLEASE show us representative data that you want to process and corresponding output in the format you really want to get. If you would have shown us the actual diagnostic message(s) you got from awk
we wouldn't have to guess whether your version of awk
does not recognize a single quote as a printf
numeric format flag or if you just didn't know how to include a single quote in a single quoted string.