I am new to ruby and trying to do a diff on two csv files.
I am putting each row into an array and then subtracting the arrays into
a new array, then taking that array and printing out the records.
The problem I am running into is I would like the badRecords method to
return the actual record lines that are not present in csv2.csv but
instead it is returning all records in csv1.csv. The other problem I see
is the code is running rather slow, cpu usage spikes up to 99% when
running. Any insight on improvements would be appreciated.
#!/usr/bin/env ruby -wKU
getNumber = FCSV.open(“csv1.csv”)
getNumber.collect do |row|
getNumber = FCSV.open(“csv2.csv”)
getNumber.collect do |row| if (row.include?(“Originating”)) &&
SumArray = Array1 - Array2 if SumArray.empty? puts "records have been validated" Process.exit!(0) else return SumArray
my_file = File.open(‘badRecords.csv’,‘w’)
records = FCSV.open(“csv1.csv”)
records.collect do |row| row.eql?(SumArray)
my_file.puts row.inspect.gsub(/[|[a-z]*]$/, “”)