In Ruby, what's the most efficient way to convert a file of tab-separated values into CSV?
Use FasterCSV
require 'rubygems'
require 'fastercsv'
FasterCSV.open("path/to/file.csv", "w") do |csv|
File.open("/path/to/file.tsv") do |f|
f.each_line do |tsv|
tsv.chomp!
csv << tsv.split(/\t/)
end
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With