Compare 2 Text Files and Output only matches to a third text file

This topic contains 1 reply, has 1 voice, and was last updated by Profile photo of Preenesh Nayanasudhan Preenesh Nayanasudhan 1 year, 6 months ago.

  • Author
  • #24368


    This is what I am trying do to compare 2 text file Old.txt and New.txt that has a few names, just need to output the names that are on both the file to a file called duplicate.txt below is what I am running

    compare-object (get-content Old.txt) (get-content New.txt) | Out-File duplicate.txt

    Here is the problem the file duplicate.txt show all the names that are on the file Old.txt.. I have also made sure that only one name is common on both file.

    Could someone please help and tell me what I am doing wrong.

    Thanks !!

  • #24370

    Figured it out.. Thanks !!

    Here it is in case someone is interested.

    $oldlist = get-content old.txt
    get-content New.txt | where {$oldlist -contains $_} | Out-File duplicate.txt

    Thanks !!

You must be logged in to reply to this topic.