How can i count the number of unique instances of IP address in the following string in ruby

Posted by kamal on Stack Overflow See other posts from Stack Overflow or by kamal
Published on 2010-06-06T22:03:26Z Indexed on 2010/06/06 22:12 UTC
Read the original article Hit count: 389

Filed under:
|

"10.1.3.1" "10.1.3.1" "10.1.3.1" "10.1.3.1" "10.1.3.1" "10.1.3.1" "10.1.3.1" "10.1.3.1" "10.1.3.1" "10.1.3.1" "10.1.3.1" "10.1.3.1" nil "10.1.3.4" "10.1.3.4" "10.1.3.4" "10.1.3.4" "10.1.3.4" "10.1.3.4" "10.1.3.4" "10.1.3.4" "10.1.3.4" "10.1.3.4" "10.1.3.4" "10.1.3.4" nil "10.1.3.10" "10.1.3.10" "10.1.3.10" "10.1.3.10" "10.1.3.10" "10.1.3.10" "10.1.3.10" "10.1.3.10" "10.1.3.10" "10.1.3.10" "10.1.3.10" "10.1.3.10" nil "10.1.3.11" "10.1.3.11" "10.1.3.11" "10.1.3.11" "10.1.3.11" "10.1.3.11" "10.1.3.11" "10.1.3.11" "10.1.3.11" "10.1.3.11" "10.1.3.11" nil "10.1.3.12" "10.1.3.12" "10.1.3.12" "10.1.3.12" "10.1.3.12" "10.1.3.12" "10.1.3.12" "10.1.3.12" "10.1.3.12" "10.1.3.12" "10.1.3.12" nil "10.1.3.30" "10.1.3.30" nil "10.1.3.38" "10.1.3.38" "10.1.3.38" "10.1.3.38" "10.1.3.38" nil "10.1.3.55" "10.1.3.55" "10.1.3.55" "10.1.3.55" "10.1.3.55" "10.1.3.55" "10.1.3.55" "10.1.3.55" "10.1.3.55" "10.1.3.55" "10.1.3.55" "10.1.3.55" "10.1.3.55" "10.1.3.55" "10.1.3.55" "10.1.3.55" "10.1.3.55" "10.1.3.55" "10.1.3.55" "10.1.3.55" "10.1.3.55" "10.1.3.55" "10.1.3.55" "10.1.3.55" "10.1.3.55" "10.1.3.55" "10.1.3.55" "10.1.3.55" "10.1.3.55" "10.1.3.55" nil "10.1.3.60" "10.1.3.60" "10.1.3.60" "10.1.3.60" "10.1.3.60" "10.1.3.60" "10.1.3.60" nil "10.1.3.66" "10.1.3.66" "10.1.3.66" "10.1.3.66" "10.1.3.66" "10.1.3.66" "10.1.3.66" nil "10.1.3.101" "10.1.3.101" nil "10.1.3.102" "10.1.3.102" "10.1.3.102" "10.1.3.102" "10.1.3.102" "10.1.3.102" "10.1.3.102" "10.1.3.102" "10.1.3.102" "10.1.3.102" "10.1.3.102" "10.1.3.102" "10.1.3.102" "10.1.3.102" "10.1.3.102" "10.1.3.102" "10.1.3.102" "10.1.3.102" "10.1.3.102" "10.1.3.102" "10.1.3.102" "10.1.3.102" nil "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" "10.1.3.103" nil "10.1.3.104" "10.1.3.104" nil "10.1.3.106" "10.1.3.106" nil "10.1.3.107" "10.1.3.107" "10.1.3.107" "10.1.3.107" "10.1.3.107" "10.1.3.107" "10.1.3.107" nil "10.1.3.108" "10.1.3.108" "10.1.3.108" "10.1.3.108" "10.1.3.108" "10.1.3.108" nil "10.1.3.110" "10.1.3.110" "10.1.3.110" "10.1.3.110" "10.1.3.110" nil

the above string is stdout of:

#!/usr/bin/ruby

require "rubygems"
require "fastercsv"


scannedIPs = Hash.new(0)

count = 0
FCSV.foreach("HOUND-1.csv", :headers => true, :skip_blanks => false) do |row|

       text = row[1]
       p text

end 

© Stack Overflow or respective owner

Related posts about ruby

Related posts about parse