Sha256: 1f7bafd95ae6d0c1b8bec6a264f30b046effaac4d16f59484595dd01c88a5b97
Contents?: true
Size: 708 Bytes
Versions: 18
Compression:
Stored size: 708 Bytes
Contents
module Wukong module Streamer # # For each identical line in the map phase output, emit one representative # line followed by the count of occrrences (separated by a tab). # # (This is the functional equivalent of +'uniq -c'+) # class CountLines < Wukong::Streamer::Base def formatted_count item, key_count "%s\t%10d" % [item, key_count.to_i] end # # Delegate to +uniq -c+, but put the count last for idempotence. # def stream %x{/usr/bin/uniq -c}.split("\n").each do |line| key_count, item = line.chomp.strip.split(/\s+/, 2) puts formatted_count(item, key_count) end end end end end
Version data entries
18 entries across 18 versions & 2 rubygems