BEGIN { FS = "," SUBSEP = ":::" } { split($NF,Plans," ") for(key in Plans) { arr[$1,Plans[key]]++ } } END { for (key in arr) { sorted[++I] = key"="arr[key] } asort(sorted) for (i = 1; i <= I; i++) print sorted[i] }