require "csv" a=Hash.new() CSV.foreach("test.csv"){|i| a[i[0]]=i[1]} b=Hash.new() CSV.foreach("test.csv"){|i| b[i[0]]=i[1]} d=(a.keys() + b.keys()).uniq d.each{|i| puts [i,a[i],b[i]].join(",")}
区切り文字をかえて、デフォルトは0に.
$ cat heigou.rb require "csv" a=Hash.new(0) CSV.foreach("buumu_count_food_word_list.txt",{:col_sep =>" "}){|i| a[i[1]]=i[0]} b=Hash.new(0) CSV.foreach("buumu_count_food_word_list_noun.txt",{:col_sep =>" "}){|i| b[i[1]]=i[0]} d=(a.keys() + b.keys()).uniq d.each{|i| puts [i,a[i],b[i]].join(",")}