Skip to content

Instantly share code, notes, and snippets.

@nnasaki
Created February 3, 2013 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nnasaki/4702261 to your computer and use it in GitHub Desktop.
Save nnasaki/4702261 to your computer and use it in GitHub Desktop.
CSV を変換する例。以下のように実行する。 ruby convert.rb blog.csv > convert.csv
# coding: UTF-8
require "csv"
options = {:headers => true,
:return_headers => true, :write_headers => true}
delete_columns = %w{Path FileName}
CSV.filter(options) do |row|
if row.header_row?
row << "FilePath"
delete_columns.each do |column|
row.delete(column)
end
next
end
row["Text"] << "ああ\nええ"
filePath = row["Path"]+"/"+row["FileName"]
row["FilePath"] = filePath
delete_columns.each do |column|
row.delete(column)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment