Created
February 3, 2013 15:55
-
-
Save nnasaki/4702261 to your computer and use it in GitHub Desktop.
CSV を変換する例。以下のように実行する。
ruby convert.rb blog.csv > convert.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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