Skip to content

Instantly share code, notes, and snippets.

@ngmaloney
Created July 22, 2011 17:58
Show Gist options
  • Save ngmaloney/1099989 to your computer and use it in GitHub Desktop.
Save ngmaloney/1099989 to your computer and use it in GitHub Desktop.
Quick and Dirty delta between 2 csv files
#!/usr/bin/env ruby
#
# A 30 second hack job to compare two CSV files
#
file1 = ARGV[0] ? ARGV[0] : false
file2 = ARGV[1] ? ARGV[1] : false
file1_set = []
file2_set = []
delta = []
if !file1 or !file2
puts 'File arguments required'
exit 0
end
def check_file(file, file_arg)
if !File.exists? file
puts "File argument #{file_arg} is not a valid file"
exit 0
end
end
check_file(file1,1)
check_file(file2,2)
f = File.open(file1,'r').read
f.each_line do |line|
file1_set.push line.strip
end
f = File.open(file2,'r').read
f.each_line do |line|
file2_set.push line.strip
end
file2_set.each do |f2|
delta.push(f2) if !file1_set.include?(f2)
end
delta.each do |row|
puts row
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment