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

后端 未结 5 799
傲寒
傲寒 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:22

    Try this Join-Object.
    It has a few more features along with joining based on multiple columns:

    $Left = ConvertFrom-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
    588496260,User4,John,05/23/1960
    565465465,User5,Jack,07/08/2020
    "@
    
    $Right = ConvertFrom-Csv @"
    First_Name,Last_Name,DOB,City,Document_Type,Filename
    User1,Micah,11/01/1969,Parker,Transcript,T4IJZSYO.pdf
    User2,Acker,05/28/1960,,Transcript,R4IKTRYN.pdf
    User3,Aco,06/26/1950,,Transcript,R4IKTHMK.pdf
    User4,John,05/23/1960,,Letter,R4IKTHSL.pdf
    "@
    
    $Left | Join $Right `
        -On First_Name, Last_Name, DOB `
        -Property Ref_ID, Filename, First_Name, DOB, Last_Name `
        | Format-Table
    
    Last_Name    Ref_ID DOB                    Filename     First_Name
    ---------    ------ ---                    --------     ----------
    Micah     321364060 1969-11-01 12:00:00 AM T4IJZSYO.pdf User1
    Acker     946497594 1960-05-28 12:00:00 AM R4IKTRYN.pdf User2
    Aco       887327716 1950-06-26 12:00:00 AM R4IKTHMK.pdf User3
    John      588496260 1960-05-23 12:00:00 AM R4IKTHSL.pdf User4
    

提交回复
热议问题