我有兩個文本文件,master.txt和926.txt。如果926.txt中有一行不在master.txt中,那麼我想寫入一個新文件notin.txt。試圖比較兩個文本文件,並根據信息創建第三個
我寫了我能想到的最好的東西,但鑑於我是一個可怕的/新手程序員失敗了。下面是我有
g = File.new("notinbook.txt", "w")
File.open("926.txt", "r") do |f|
while (line = f.gets)
x = line.chomp
if
File.open("master.txt","w") do |h|
end
while (line = h.gets)
if line.chomp != x
puts line
end
end
end
end
end
g.close
當然,它失敗。謝謝!
我修改你的代碼試圖保持這個想法,所以你可以看到所缺乏的(你是接近!)https://開頭gist.github.com/1252609雖然這樣做的意思是幾次運行master.txt的同一行,所以效率不高,但它完成了工作。 – derp