0

Following Problem:

We have 2 csv files with a few differences in them. Now we want to compare these two via a unique number that is already included in both files and output the rows where a difference was found (anywhere in that row) into a seperate csv with the header included. All that should be done in Powershell. It is important that the output file has the exact same formating as the files we are comparing. Also our csv files have a total of ~90 Cells in width and around ~1000 rows.

Does anyone have an idea how this could work?

  • 1
    Welcome to SO. Note that SO isn't a free code service. I suggest you play around with a small CSV file and PS's CSV cmdlets. You will quickly find that PS transforms lines into objects, that you can inspect in various ways. – Rno Sep 14 '20 at 15:33
  • 1
    What exactly are you looking to output? If there is a difference on the given object do you want to output both instances from File1 & file2? Do you want to output instances where an object is in one file instance but not the other? Since you are new you may find it helpful to read [How do I ask a good question](https://meta.stackoverflow.com/search?q=how+to+ask+a+good+question) – Steven Sep 14 '20 at 15:50
  • Does this answer your question: [In Powershell, what's the best way to join two tables into one?](https://stackoverflow.com/a/45483110/1701026) – iRon Sep 14 '20 at 16:47

1 Answers1

1

you can try to import both csv files and compare it with Compare-Object like this:

$CSV1 = "Path to CSV1"
$CSV2 = "Path to CSV2"

$ImportedCSV1 = Import-Csv $CSV1
$ImportedCSV2 = Import-Csv $CSV2

Compare-Object -ReferenceObject $CSV1 -DifferenceObject $CSV2
LosFla
  • 99
  • 6