Advertisement
Guest User

Untitled

a guest
Sep 16th, 2014
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. diff <(cut -d, -f2 file1) <(cut -d, -f3 file2)
  2.  
  3. def identical_files?(file1, field1, file2, field2)
  4. %x{diff <(cut -d, -f#{field1} #{file1}) <(cut -d, -f#{field2} #{file2})}.blank?
  5. end
  6.  
  7. `bash -c 'cat <(echo foo)'` #=> "foo"
  8.  
  9. require 'csv'
  10.  
  11. csv_file1 = CSV.open('file1')
  12. csv_file2 = CSV.open('file2')
  13.  
  14. until (csv_file1.eof? || csv_file2.eof?) do
  15. row1 = csv_file1.shift
  16. row2 = csv_file2.shift
  17.  
  18. # do something to diff the fields
  19. puts "#{ csv_file1.lineno }: #{ row1[1] } == #{ row2[2] } --> #{ row1[1] == row2[2] }"
  20. end
  21.  
  22. [
  23. [csv_file1, 'file1'],
  24. [csv_file2, 'file2']
  25. ].each do |f, fn|
  26. puts "Hit EOF for #{ fn }" if f.eof?
  27. f.close
  28. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement