Compare 2 header of a csv file

Tagged: 

This topic contains 3 replies, has 3 voices, and was last updated by Profile photo of Dave Wyatt Dave Wyatt 1 year, 1 month ago.

  • Author
    Posts
  • #32946
    Profile photo of Papa
    Papa
    Participant

    I have 2 csv files as like below
    First.csv
    Header1,Header2
    abc,xyz

    2nd.csv
    Header1
    abc

    The output I expect is as below
    Header1,Header2, Header3
    abc,xyz,Comment

    I am trying to use the below script but not just able to put it in place.

    $CSV1 = C:\Path\To\File1.csv
    $CSV2 = C:\Path\To\File2.csv
    $CSV1|ForEach{$_|Add-Member 'Name ID' $Null}
    ForEach($Record in $CSV1){
    $Record.'Name ID' = $CSV2|Where{$_.ID -eq $Record.ID}|Select -Expand 'Name ID'
    }

  • #32953
    Profile photo of Steven Ayers
    Steven Ayers
    Participant

    I'd love to help, but your post doesn't really make sense.

    Is Header3 meant to include a comment saying "Header 1 value Exists in both spreadsheets" or something along those lines?

  • #32961
    Profile photo of Papa
    Papa
    Participant

    Header3 can contain any custom comment say "ok The value is available"

  • #32962
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    You probably want something like Join-Object: http://blogs.msdn.com/b/powershell/archive/2012/07/13/join-object.aspx

You must be logged in to reply to this topic.