BEGIN { FS = OFS = "," Best[0] = 0 MaxKeep = 10 } { classify($NF, Best, MaxKeep) } END { for (i = 1; i <= getsize(Best); i++) print Best[i] } #in bestlist keep maxkeep items sorted highest to lowest #newval = sweet data, bestlist = array, maxkeep = int function classify(newval, bestlist, maxkeep, i, j) { if (getsize(bestlist) > 0) { #list has stuff in it, find if/where to insert for (i = 1; i <= getsize(bestlist); i++) { if (newval > bestlist[i]) { #sort highest to lowest if(getsize(bestlist) < maxkeep) setsize(bestlist,getsize(bestlist) + 1) insertsorted(bestlist, i, newval) break #done } } } else if (getsize(bestlist) == 0) { bestlist[1] = newval setsize(bestlist,getsize(bestlist) + 1) } else barph("Why does this array have an invalid size oh God I'm confused") } #WORST. ERROR REPORTING. EVER. function barph(errstr) { print errstr exit }