Compare Two CSVs, match the columns on 2 or more Columns, export specific columns from both csvs with powershell

后端 未结 5 780
傲寒
傲寒 2021-01-24 06:33

i Have 2 CSV\'s

left.csv

Ref_ID,First_Name,Last_Name,DOB
321364060,User1,Micah,11/01/1969
946497594,User2,Acker,05/28/1960
887327716,User3,Aco,06/26/1950         


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-24 07:12

    adding answer i found:

    $left = Import-Csv .\left.csv
    $right = Import-Csv .\right.csv
    
    $right | foreach { 
        $r = $_; 
        $left | where{ $_.First_Name -eq $r.First_Name -and $_.Last_Name -eq $r.Last_Name -and $_.DOB -eq $r.DOB } | 
            select Ref_Id, 
                First_Name, 
                Last_Name, 
                DOB, 
                @{Name="City";Expression={$r.City}}, 
                @{Name="Document_Type";Expression={$r.Document_Type}}, 
                @{Name="FileName";Expression={$r.FileName}}
    } | format-table
    

提交回复
热议问题