stat = Hash.new(0) for line in ARGF w = line.chomp.split(/\s*,\s*/) c = w[0][-4,4] k = format("%4s Ed%u Ctr%03u Subctr%03u", c, w[1], w[2], w[3]) stat[k] += 1 end for k in stat.keys.sort print "#{k}\t#{stat[k]}\r\n" end