Skip to content

Instantly share code, notes, and snippets.

@Olefine
Created February 28, 2014 12:30
Show Gist options
  • Save Olefine/9270261 to your computer and use it in GitHub Desktop.
Save Olefine/9270261 to your computer and use it in GitHub Desktop.
merging files
require 'pry-debugger'
output = File.new("output.txt", 'a')
nm1 = File.open("names.txt", 'r')
nm2 = File.open("names2.txt", "r")
#binding.pry
nm1.each_line do |n1|
nm2.each_line do |n2|
case n1 <=> n2
when -1 then output.write n1; output.write n2
when 0 then output.write n1
when 1 then output.write n2; output.write n1
end
break
end
end
output.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment