Skip to content

Instantly share code, notes, and snippets.

@bradland
Created June 4, 2013 19:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradland/5708806 to your computer and use it in GitHub Desktop.
Save bradland/5708806 to your computer and use it in GitHub Desktop.
Cleans up CSV files
#!/usr/bin/env ruby
require 'csv'
require 'iconv'
def clean(string)
# Tranlit to ASCII
string = Iconv.new('ASCII//TRANSLIT', 'UTF-8').iconv(string)
# Trim whitepsace
string = string.chomp
# Return the cleaned up string
string
end
CSV.foreach(File.expand_path(ARGV[0])) do |line|
puts line.map!{|i| clean(i)}.to_csv
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment