Created
April 24, 2016 15:44
-
-
Save masakid/abefc26ac27a288f3f58432d64e53a90 to your computer and use it in GitHub Desktop.
VLOOKUPの代わりのスクリプト
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
#! ruby | |
require 'csv' | |
## ファイル読み込み | |
# 人事提供ファイル | |
jinji_table = CSV.table(ARGV[0]) | |
# 認証基盤ファイル | |
ninshou_table = CSV.table(ARGV[1]) | |
## ファイル比較と配列作成 | |
hash = {} | |
# ファイルを解析して、認証ファイルハッシュを作成、ldapid => CSV.row | |
ninshou_table.each do |ninshou| | |
hash[ninshou[:ldapid]] = ninshou | |
end | |
# 人事ファイルを走査して、認証ファイルハッシュからデータを取得し配列作成 | |
arr = [] | |
non_arr = [] | |
jinji_table.each do |jinji| | |
if hash.has_key?(jinji[:ldapid]) | |
arr << [jinji[:ldapid], | |
jinji[:sex], | |
jinji[:job], | |
hash[jinji[:ldapid]][:employeeid], | |
hash[jinji[:ldapid]][:name]] | |
else | |
non_arr << [jinji[:ldapid], | |
jinji[:sex], | |
jinji[:job]] | |
end | |
end | |
# ファイル出力 | |
CSV.open("mix.csv", "w", :encoding => "SJIS") do |writer| | |
arr.each do |str| | |
writer << str | |
end | |
end | |
CSV.open("out.csv", "w", :encoding => "SJIS") do |writer| | |
non_arr.each do |str| | |
writer << str | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment