i have to compare two Csv files which are populated by an ecommerce. The files are always similar, except that the newer ones have a different number of items, because the catalogue changes every week.
Example of the CSV file:
sku_code, description, price, url
001, product one, 100, www.something.com/1
002, prouct two, 150, www.something.com/2
By comparing two files extracted on different days, i would like to produce a list of products which have been discontinued and another list of products which have been added.
My index should be the Sku_code, which is univocal inside the catalogue.
I've been using this code from stackoverflow:
#old file
f1 = IO.readlines("oldfeed.csv").map(&:chomp)
#new file
f2 = IO.readlines("newfeed.csv").map(&:chomp)
#find new products
File.open("new_products.txt","w"){ |f| f.write((f2-f1).join("\n")) }
#find old products
File.open("deleted_products.txt","w"){ |f| f.write((f1-f2).join("\n")) }
My issue
It works well, except in one case: when one of the fields after the sku_code is changed, the products is considered "new" (eg: a change of price ) even though for my needs, it's the same product.
What it the smartest way to compare only the sku_code instead of the whole row?