jiam912
November 27, 2016, 4:32pm
22
Hi RudiC
I try to do it
for (l in LNC)
{printf "%d", l | cmdsort
for (IX=1; IX<=CNTLM+1; IX++) {printf "\t%d", CNT[l,IX]+0 | cmdsort
NNUL[IX] += CNT[l,IX]>0
MIN[IX]=$IX
MAX[IX]=$IX
print DASHES
printf "TbyM"
for (IX=1; IX<=CNTLM+1; IX++) printf "\t%d", MIN[IX]
print DASHES
printf "TbyM"
for (IX=1; IX<=CNTLM+1; IX++) printf "\t%d", MAX[IX]
But it does not work
about the dash replacement for the zeroes.. i try to use the
gsub
but it fails ...
RudiC
November 28, 2016, 6:36am
23
It always helps to SHOW WHAT "does not work" or what fails.
Your printout can't work as the values are incorrectly collected - in the END, i.e. printout section. There, the values are no more available; you need to collect them during the body operation.
Try
awk -F, -vCATS="-10,-5,0,15,25,35,50" '
BEGIN {CNTLM = split (CATS, LMT)
# LMT[CNTLM+1] = "50+"
for (IX=1; IX<=CNTLM+1; IX++) {MIN[IX] = "-"
MAX[IX] = "-"
}
cmdsort = "sort -n"
while (length(DASHES) < 8*(CNTLM+3)) DASHES = DASHES "--------"
}
function PR(NM, AR, FMT, LST) {print DASHES
printf NM
for (IX=1; IX<=CNTLM+1; IX++) printf FMT, AR[IX]
printf LST RS
}
{for (IX=1; IX<=CNTLM && $10>LMT[IX]; IX++); # semicolon is mandatory!
if (MIN[IX] == "-" || $10 < MIN[IX]) MIN[IX] = $10
if (MAX[IX] == "-" || $10 > MAX[IX]) MAX[IX] = $10
CNT[$6,IX]++
COLTOT[IX]++
LNC[$6]++
TOT++
}
END {printf "FLD6"
for (IX=1; IX<=CNTLM; IX++) printf "\t%6s", "<=" LMT[IX]
printf "\t%6s\t TbyV" RS, ">" LMT[--IX]
print DASHES
for (l in LNC)
{printf "%4d", l | cmdsort
for (IX=1; IX<=CNTLM+1; IX++) if (CNT[l,IX] > 0) {printf "\t%6d", CNT[l,IX] | cmdsort
NNUL[IX] ++
}
else printf "\t -" | cmdsort
printf "\t= %6d" RS, LNC[l] | cmdsort
}
close (cmdsort)
for (IX=1; IX<=CNTLM+1; IX++) COLAVG[IX] = COLTOT[IX] / TOT
PR("TbyH", COLTOT, "\t%6d", " = " TOT)
PR("TAVG", COLAVG, "\t%.4f")
PR("TMIN", MIN, "\t%6s")
PR("TMAX", MAX, "\t%6s")
PR("TViU", NNUL, "\t%6d")
}
' /tmp/tmp1.txt
FLD6 <=-10 <=-5 <=0 <=15 <=25 <=35 <=50 >50 TbyV
--------------------------------------------------------------------------------
2 - - 2 1091 118 9 1 - = 1221
8 - - 4 1193 3 1 - - = 1201
9 - - 2 1180 3 - - - = 1185
10 - - 2 750 24 3 - - = 779
12 - - 2 967 31 - - - = 1000
13 - - 3 967 4 - - - = 974
14 - - - 369 7 1 - - = 377
15 - - 4 916 19 - - - = 939
18 - - 2 769 6 1 - - = 778
22 - - 2 1034 169 12 - - = 1217
24 - - 3 1154 24 - - - = 1181
28 - - - 1100 48 7 1 - = 1156
--------------------------------------------------------------------------------
TbyH 0 0 26 11490 456 34 2 0 = 12008
--------------------------------------------------------------------------------
TAVG 0.0000 0.0000 0.0022 0.9569 0.0380 0.0028 0.0002 0.0000
--------------------------------------------------------------------------------
TMIN - - 0 8 16 26 39 -
--------------------------------------------------------------------------------
TMAX - - 0 15 25 31 40 -
--------------------------------------------------------------------------------
TViU 0 0 10 12 12 7 2 0
jiam912
November 28, 2016, 11:17am
24
Dear RudiC.
It is great .. many thanks..
I see the values minimum and maximum are not correct... for example in column 5 should be
min = 369 max = 1193
. but is not the case... I am trying to figure out that..
Thanks a lot
RudiC
November 28, 2016, 11:31am
25
Oh, now I get the requirement. What if you had explained it clearly in the first place?