Last active
May 31, 2017 05:59
-
-
Save ugdark/4b5e439b3be46632171d3fcd456cceb4 to your computer and use it in GitHub Desktop.
ruby 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
CSV.open("/Users/a_nishiyama/Kokodayo.com/ruby_examples/data/sample_new.csv", 'w') do |write| | |
CSV.foreach("/Users/a_nishiyama/Kokodayo.com/ruby_examples/data/sample.csv") do |columns| | |
# columns.each {|header, field| field += "test";p field } | |
# columns.each { |head, field| columns[head] = "test" } | |
columns.unshift("hoge") # 行の先頭に追加 | |
columns[1] = "置換" # 行の置き換え | |
columns.push $. == 1 ? 'head' : 'hoge' # 行の先頭に追加 | |
write << columns | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment