Skip to content

Instantly share code, notes, and snippets.

@rahearn
Created July 8, 2016 14:42
Show Gist options
  • Save rahearn/08378a974c9b78afd21f216a563a763f to your computer and use it in GitHub Desktop.
Save rahearn/08378a974c9b78afd21f216a563a763f to your computer and use it in GitHub Desktop.
translate pipe-delimited files to CSV
require 'csv'
path = ARGV[0]
fail "path required" if path.nil?
csv = CSV.open "#{path}.csv", "w"
begin
File.open(path).each do |line|
line = line.strip.force_encoding('iso-8859-1').encode 'UTF-8'
csv << line.split('|', -1)
end
ensure
csv.close
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment