开发者

TSV --> CSV in Ruby

开发者 https://www.devze.com 2023-01-30 08:49 出处:网络
In Ruby, what\'s the most efficient way to convert a fi开发者_Go百科le of tab-separated values into CSV?Use FasterCSV

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

精彩评论

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