开发者

TSV --> CSV in Ruby

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜