Skip to content

Instantly share code, notes, and snippets.

@luikore
Created September 24, 2009 17:03
Show Gist options
  • Save luikore/192874 to your computer and use it in GitHub Desktop.
Save luikore/192874 to your computer and use it in GitHub Desktop.
require 'iconv'
require 'rubygems'
require 'ipparse'
write_now = Time.now
counts = {}
comma = ','
open "member22.csv" do |f|
loop do
f.gets comma
break if f.eof?
f.gets comma
ip = f.gets(comma).chop
if counts[ip]
counts[ip] += 1
else
counts[ip] = 1
end
end
end
open "countMember22.csv", 'w' do |f|
Iconv.open 'GBK', 'UTF-8' do |i|
counts.each {|k, v| f.puts "#{i.iconv IPParse.parse k} #{v}" }
end
end
puts Time.now - write_now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment