In ruby, I am trying to compare a list of URLs with a previous list of URLs, and get only the new ones.
I put the old list in a text file with one URL per line. I am reading the text file into an array like so:
oldLines = File.open('logfile.txt', 'r').readlines
I have an array of new values populated using the exact same method as the old list, and will probably have some overlap with the old list called ‘newLines’. I am trying to get only values that don’t match with the old list. Let’s say ‘newList’.length = 100 and ‘oldlist’.length = 95, and I know through visual inspection that something like 90 elements overlap between them.
Things I have tried:
newList = newList - oldList
#(newList | oldList) returns 195
#(newList & oldList) returns 0
newList.delete_if { |x| oldList.include?(x) }
In both scenarios, nothing gets deleted from newList. I know I am missing something here. Thanks.
I did the following:
a.txt
b.txt
test.rb
Without the
chompit fails because ina.txtI havehttp://yahoo.com\nwhile onb.txtI simply havehttp://yahoo.comwithout the\nat the end.