Skip to content

Instantly share code, notes, and snippets.

@mmiliaus
Created May 27, 2013 22:39
Show Gist options
  • Save mmiliaus/5659418 to your computer and use it in GitHub Desktop.
Save mmiliaus/5659418 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
posts_count = 0
last_key = nil
STDIN.each_line do |line|
key, value = line.split("\t")
if last_key && last_key != key
puts "#{last_key}\t#{posts_count}"
last_key, posts_count = key, value.to_i
else
last_key = key
posts_count += value.to_i
end
end
puts "#{last_key}\t#{posts_count}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment