Created
September 13, 2018 13:29
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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