Skip to content

Instantly share code, notes, and snippets.

@harry-wood
Created September 13, 2018 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harry-wood/e09ef370223d6558f0dac5a41b8b0303 to your computer and use it in GitHub Desktop.
Save harry-wood/e09ef370223d6558f0dac5a41b8b0303 to your computer and use it in GitHub Desktop.
Spit out any lines which are in the first file and not in the second
#!/usr/local/bin/ruby -w
# Assuming the two files are sorted, this will walk through them in parallel comparing
# and spitting out any lines which are in the first one and not in the second.
# its equivalend to the unix command: diff A.txt B.txt|grep '^<'|awk '{print $2}'
fa = File.open(ARGV[0])
fb = File.open(ARGV[1])
linea = nil
lineb = nil
loop do
if linea==lineb
linea = fa.gets || break
lineb = fb.gets || ""
elsif linea<lineb
puts linea
linea = fa.gets || break
elsif linea>lineb
lineb = fb.gets || ""
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment