Skip to content

Instantly share code, notes, and snippets.

@dbreunig
Last active January 20, 2020 03:55
Show Gist options
  • Save dbreunig/b7277a85770d5bef7d7e to your computer and use it in GitHub Desktop.
Save dbreunig/b7277a85770d5bef7d7e to your computer and use it in GitHub Desktop.
A quick and dirty script to convert pipe separated files (PSV) to comma separated files (CSV)
require 'csv'
psv_file = ARGV[0]
csv_loc = ARGV[1]
if psv_file =~ /psv/ && csv_loc =~ /csv/
CSV.open(csv_loc, "wb") do |csv|
File.open(psv_file, "r").each_line do |line|
row = line.split('|')
csv << row
end
end
else
puts "USAGE: psv2csv.rb [psv file] [path to csv file to write]"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment