Reputation: 1922
In Ruby, what's the most efficient way to convert a file of tab-separated values into CSV?
Upvotes: 3
Views: 3360
Reputation: 2706
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
Upvotes: 4