rubyでファイルの併合3 (共通するもの対応関係の出力)

rubyでファイルの併合3
(共通するもの対応関係の出力)

f=open("A.txt");

a=Hash::new();
k=1;
f.readlines.each{|i|
        i.chomp!
        q=i.split(" ")
        a[q[0]]=q[0]+" "+k.to_s;
        k=k+1;

}

f3=open("B.txt");
b=Hash::new();

k=1;
f3.readlines.each{|i|
        i.chomp!
        q=i.split(" ")

        b[q[0]]=q[0]+" "+k.to_s;
        k=k+1;
}


f2=open("shyokulist.txt");
f2.readlines.each{|i|

        i.chomp!



        if a.has_key?(i) && b.has_key?(i) then
                puts "A & B "+a[i].to_s+" "+b[i]
        end

        if a.has_key?(i) && !b.has_key?(i) then
                puts "A "+a[i].to_s
        end


        if !a.has_key?(i) && b.has_key?(i) then
                puts "B "+b[i].to_s
        end
}