Remove excessive occurrences
AWK -vn=, 9
a[$1]++&lt;n

This is so competitive with the golfing-language answers, I feel like I might have misunderstood the question - did I?
The limit n is passed as a variable at the command line with -vn=&lt;value&gt;. The array is read from STDIN.
Try it online!