我有一個檔案first.csv
name,surname,height,city,county,state,zipCode
John,Doe,120,jefferson,Riverside,NJ,8075
Jack,Yan,220,Phila,Riverside,PA,9119
Jill,Fan,120,jefferson,Riverside,NJ,8075
Steve,Tan,220,Phila,Riverside,PA,9119
Alpha,Fan,120,jefferson,Riverside,NJ,8075
和second.csv
name,surname,height,city,county,state,zipCode
John,Doe,120,jefferson,Riverside,NJ,8075
Jack,Yan,220,Phila,Riverside,PA,9119
Jill,Fan,120,jefferson,Riverside,NJ,8075
Steve,Tan,220,Phila,Riverside,PA,9119
Bravo,Tan,220,Phila,Riverside,PA,9119
我想比較first.csv和second.csv檔案的行,并輸出first.csv或second.csv中但不在兩者中的行。
所以output.csv應該有
Alpha,Fan,120,jefferson,Riverside,NJ,8075
Bravo,Tan,220,Phila,Riverside,PA,9119
有很多類似的問題,但輸出并不完全是我想要的。
謝謝
uj5u.com熱心網友回復:
$filea = Import-Csv C:\Powershell\TestCSVs\group1.csv
$fileb = Import-Csv C:\Powershell\TestCSVs\group2.csv
Compare-Object $filea $fileb -Property name, surname, height, city, county, state, zipCode | Select-Object name, surname, height, city, county, state, zipCode | export-csv C:\Powershell\TestCSVs\out.csv -NoTypeInformation
我在這里使用所有欄位進行比較和排序,但您可以指定要用于匹配行的唯一值。
輸出
"name","surname","height","city","county","state","zipCode"
"Bravo","Tan","220","Phila","Riverside","PA","9119"
"Alpha","Fan","120","jefferson","Riverside","NJ","8075"
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/460720.html
