Compare files

  • I need a simply file compare of 2 files with no headers, but the 5th column in both files contains a value that has dates, and the 1st,2nd,3rd columns have values that can correlate to entity,account,subacct that also could be used for uniqueness. I tried to use this script but didn't produce the results expected. I would just like a 3rd file showing diff's.

    Thanks

    Clear-Host
    $strReference = Get-Content "c:\glrepts\detail.augfinal.txt"
    $strDifference = Get-Content "c:\glrepts\detail_pm.txt"
    Compare-Object -referenceObject $strReference -differenceObject $strDifference `
    -syncWindow 100 -includeEqual
  • Bruin wrote:

    I need a simply file compare of 2 files with no headers, but the 5th column in both files contains a value that has dates, and the 1st,2nd,3rd columns have values that can correlate to entity,account,subacct that also could be used for uniqueness. I tried to use this script but didn't produce the results expected. I would just like a 3rd file showing diff's. Thanks

    Clear-Host
    $strReference = Get-Content "c:\glrepts\detail.augfinal.txt"
    $strDifference = Get-Content "c:\glrepts\detail_pm.txt"
    Compare-Object -referenceObject $strReference -differenceObject $strDifference `
    -syncWindow 100 -includeEqual

    You've provided a requirement, but not asked any questions.

    If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.
    See https://www.sqlservercentral.com/articles/forum-etiquette-how-to-post-datacode-on-a-forum-to-get-the-best-help/ for details of how to post T-SQL code-related questions.

  • How do you turn the above script into my requirement.

    Thx.

  • Well why are you using -includeequal if you just want the diffs 🙂

     

  • Maybe that's what I'm trying to ask, how do I only show diff's based upon columns that could be used for sort or key.

    Thanks.

  • Compare-Object is comparing the entire object, in the case of files it'll compare the entire line and you'll see all the lines that are in one file or the other.  Powershell is not ideal for doing column based compares.

  • Any suggestions?

  • Well this is a SQL forum 🙂  So load it to a database and do a full outer join on what you consider the key columns, then you can do whatever other compares/sorts you need.

  • sounds like a plan.

     

    Thx.

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic. Login to reply