Created
January 20, 2012 15:34
-
-
Save rymawby/1647904 to your computer and use it in GitHub Desktop.
Ruby script to compare two text files - analysed what lines exist in file1 that do not in file2.
This file contains 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/bin/ruby | |
# script to compare and see what lines are in file1 but not file2 | |
f1 = File.open('file1.txt') | |
f2 = File.open('file2.txt') | |
file1lines = f1.readlines | |
file2lines = f2.readlines | |
file1lines.each do |e| | |
if(!file2lines.include?(e)) | |
puts e | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello...
How about if you want to compare two files if everything in file1.txt matches that in file2.txt?
And if file2.txt is shorter, it should copy the remaining lines from file1.txt into it