简体   繁体   English

比较Powershell中的2个CSV文件并输出差异

[英]Comparing 2 CSV files in Powershell and output the differences

Following Problem:以下问题:

We have 2 csv files with a few differences in them.我们有 2 个 csv 文件,其中有一些差异。 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.现在我们想通过一个已经包含在两个文件中的唯一编号来比较这两者,并将发现差异的行(该行中的任何地方)输出到包含标题的单独 csv 中。 All that should be done in Powershell.所有这些都应该在 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.此外,我们的 csv 文件总共有大约 90 个单元格的宽度和大约 1000 行。

Does anyone have an idea how this could work?有谁知道这是如何工作的?

you can try to import both csv files and compare it with Compare-Object like this:您可以尝试导入两个 csv 文件并将其与比较对象进行比较,如下所示:

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

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

Compare-Object -ReferenceObject $CSV1 -DifferenceObject $CSV2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM