Created
January 6, 2012 10:50
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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