chris
3/23/2007 9:43:00 AM
Hi,
i'm new to ruby.
How could i read a tab-delimted textfile with two columns + header
row
and count the distinct values from the 2.column?
## my first experiments missed because i have to elimnate the header
row!?#######
filename = gets.chomp
text = String.new
File.open(filename) { |f| text = f.read }
values = text.split(/\t/)
freqs = Hash.new(0)
values.each { |values| freqs[values] += 1 }
freqs = freqs.sort_by {|x,y| y }
freqs.each {|values, freq| puts values+' '+freq.to_s}
Many thanks for a starting point.
regards, christian