Skip to content

Instantly share code, notes, and snippets.

@takkii takkii/sample.csv
Created May 22, 2019

Embed
What would you like to do?
CSVのサンプル
20190516 1111
20170530 2222
20190420 3333
20180520 4444
20190515 5555
20170213 1111
20190422 6666
@takkii

This comment has been minimized.

Copy link
Owner Author

commented May 22, 2019

sample.csvを読み込み(元データ、試作品)

require 'csv'

CSV.open("write-file.csv", "w") do |test|
row = CSV.read("sample.csv")
are = row.to_h.sort.reverse
are.slice!(6)
puts are.join(',')
test << are
end
@takkii

This comment has been minimized.

Copy link
Owner Author

commented May 22, 2019

write-file.csvに書き込み(加工後、試作品)

20190516 1111
20190515 5555
20190422 6666
20190420 3333
20180520 4444
20170530 2222

多少、エディタの機能で整形した結果。

@takkii

This comment has been minimized.

Copy link
Owner Author

commented May 22, 2019

20190516,1111,20190515,5555,20190422,6666,20190420,3333,20180520,4444,20170530,2222

整形前。出力結果←試行錯誤中、試作品。

@takkii

This comment has been minimized.

Copy link
Owner Author

commented May 22, 2019

整形前を処理する機能もあればいいのだろうが、エディタの機能で済むよな。
それさえもしてしまいたかったのでしました。

@takkii

This comment has been minimized.

Copy link
Owner Author

commented May 22, 2019

success

完成形はF#、BASH、VBAネタだねぇ。

@takkii

This comment has been minimized.

Copy link
Owner Author

commented May 22, 2019

書き出しているから、多少の手合わせはエディタでプログラムを書くまでもない。ぐぅ。の根も出ない。
邪念がなくなるとできるんだよな、

@takkii

This comment has been minimized.

Copy link
Owner Author

commented May 31, 2019

sample.csvを読み込み(元データ、完成形)

require 'csv'

CSV.open("write-file.csv", "w") do |test|
row = CSV.read("sample.csv")
are = row.to_h.sort.reverse
are.slice!(6)
are.join(',')
are.each_with_index do |a|
  puts "#{a.to_csv}"
  test << a
end
end

write-file.csvに書き込み(加工後、完成形)

20190516,1111
20190515,5555
20190422,6666
20190420,3333
20180520,4444
20170530,2222

これでRubyで実装できることが証明されました。使おうぜ、CSV加工にRubyを。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.