Created
May 26, 2011 15:55
-
-
Save Jxck/993406 to your computer and use it in GitHub Desktop.
Hadoop Streaming with Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
ARGF.each do |line| | |
line.chomp! | |
words = line.split(' ') | |
printf("%s,1\n", words[8]) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
counter = Hash.new | |
ARGF.each do |line| | |
line.chomp! | |
words = line.split(',') | |
word = words[0] | |
count = words[1].to_i | |
if !counter.key?(word) | |
counter[word] = 1 | |
else | |
counter[word]+=count | |
end | |
end | |
counter.each do |k, v| | |
printf("%s:%d\n", k, v) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment