Last active
January 20, 2020 03:55
-
-
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)
This file contains hidden or 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
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