awk not summing correctly?
Hi All,
Not sure if I'm just missing something here but this looks correct, I've re-written the code a bit to eliminate variables and isolate the awk statement: Code:
echo "${Mrl101Array[*]}" | tr ' ' "\n" | sort -n -t"_" Code:
16_100_sat Code:
echo "${Mrl100Array[*]}" | tr ' ' "\n" | sort -n -t"_" | awk 'BEGIN { FS = "_" } ; {sum+=$1} END { print "Average = ",sum}' Am I just overlooking a small syntax issue here? |
OK, so I was able to get it to do its math by taking the first code example and redirecting it to a tmp file then awking from that tmp file. Can anyone explain this behavior? I'm not an awk expert so not sure if it has something to do with the array expansion or what.
|
Seems to work just fine for me as is. I would mention that the sort is kind of pointless as is the tr when awk could do it all:
Code:
arr=( 30_100_mon 28_100_tue 19_100_wed 19_100_thur 26_100_fri 16_100_sat 29_100_sun ) |
All times are GMT -5. The time now is 06:47 AM. |