In Ruby, what's the most efficient way to convert a fi开发者_Go百科le 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
精彩评论