Skip to content

Instantly share code, notes, and snippets.

@nickcharlton
Created January 6, 2012 10:50
Show Gist options
  • Save nickcharlton/1570089 to your computer and use it in GitHub Desktop.
Save nickcharlton/1570089 to your computer and use it in GitHub Desktop.
A snippet for cleaning up a CSV file by removing whitespace. Messy, but works.
#!/bin/ruby
#
# Parses a given CSV file, and writes it back out.
# The CSV library handles types nicer.
#
# Author: Nick Charlton
# Date: 6/1/12
# License: MIT
#
require 'csv'
array = []
CSV.foreach('sanitised_deal_data.csv') do |row|
array << row
end
CSV.open('new_deal_data.csv', "wb") { |csv|
array.each { |e|
csv << e.each { |a|
if (a != nil )
# do some stuff to each type
a.strip!
end
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment