search
LoginSignup
7

More than 5 years have passed since last update.

posted at

Powershellで複数のCSVファイルを読み込んでSortして出力

はじめに

前回作った歩引行と実際の売上のデータ行を合成して出力します。

sales.csv
id,detail_id,item,price,discount_per,discount_price
0,1,letsnote,2000,8,160
1,1,macbookair,1230,8,98.4
2,1,macbookpro,998,8,79.84
discounts.csv
"id","detail_id","item","price","discount_per","discount_price"
"0","998","8%","-160","8","160"
"1","998","8%","-98.4","8","98.4"
"2","998","8%","-79.84","8","79.84"
2つのCSVファイルを読み込んで結合して出力
PS >$sales=Import-Csv -path sales.csv,discounts.csv
PS >$sales=$sales | sort id,detail_id
PS >$sales | Export-Csv -path sales.csv
sales.csv
"id","detail_id","item","price","discount_per","discount_price"
"0","1","letsnote","2000","8","160"
"0","998","8%","-160","8","160"
"1","1","macbookair","1230","8","98.4"
"1","998","8%","-98.4","8","98.4"
"2","1","macbookpro","998","8","79.84"
"2","998","8%","-79.84","8","79.84"

参考サイト

第2回チキチキ!シェル芸人養成勉強会をPowerShellでやってみた
の問題10: ファイルの結合

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
7