file=ARGV[0] info = Hash.new {|h,k,l,m| h[k][l][m] = 0.0 } File.open(file) do |f| while f.gets _, qn, docid, rank, score, _ = split(/\s+/) #info[qn+'_'+docid+'_'+'score'] += score.to_f info[qn][docid]['score'] += score.to_f end end p info