C# - 比较两个 CSV 文件并给出输出
需要一些帮助,我有两个信息源,并且这些信息由不同的程序导出到两个不同的 CSV 文件。它们应该包含相同的信息,但这正是需要检查的内容。
因此,我想做的是:
- 从两个文件中获取信息。
- 比较
- 输出任何差异以及差异所在的文件。(例如文件 A 包含此内容,但文件 B 不包含此内容,反之亦然)。
这些文件有 200,000 多行,因此需要尽可能有效。
尝试使用 Excel 执行此操作,但事实证明太复杂,我真的很难以编程方式找到一种方法。
Need a bit of help, I have two sources of information and the information is exported to two different CSV file's by different programs. They are supposed to include the same information, however this is what needs to be checked.
Therefore what I would like to do is as follows:
- Take the information from the two files.
- Compare
- Output any differences and which file the difference was in. (e.g File A Contained this, but File B did not and vice versa).
The files are 200,000 odd rows so will need to be as effective as possible.
Tried doing this with Excel however has proved to be too complicated and I'm really struggling to find a way programatically.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
假设这些文件确实应该是相同,就文本限定符、行的顺序以及每个文件中包含的行数而言,最简单的方法可能是简单地一起迭代两个文件并比较每一行。
Assuming that the files are really supposed to be identical, right down to text qualifiers, ordering of rows, and number of rows contained in each file, the simplest approach may be to simply iterate through both files together and compare each line.
根据您对问题评论的回答,如果确实不需要使用代码来完成,那么您可能会比下载比较工具更糟糕,这可能会更复杂。
(例如 Winmerge)
Depending on your answers to the comments on your question, if it doesn't really need to be done with code, you could do worse than download a compare tool, which is likely to more sophisticated.
(Winmerge for example)
好的,对于任何其他通过谷歌搜索并找到这个的人。这就是我的答案。
我将详细信息导出到 CSV 中,并在导出时按数字对它们进行排序,以便于使用。将它们导出为两个 CSV 文件后,我使用了一个名为
Beyond Compare
的程序,可以在 这里。这允许比较文件。起初,我手动使用 Beyond Compare 来测试我导出的内容是否正确等,但是 Beyond Compare 确实能够使用命令行进行比较。然后,一切都会以编程方式完成,所要做的就是用户在
Beyond Compare
中查看结果。您也许可以将它们导出到另一个 CSV,我还没有看到Beyond Compare
的 GUI 非常好用,所以使用它更容易。OK, for anyone else that googles this and finds this. Here is what my answer was.
I exported the details to a CSV and ordered them numerically when they were exported for ease of use. Once they were exported as two CSV files, I then used a program called
Beyond Compare
which can be found here. This allows the files to be compared.At first I used Beyond Compare manually to test what I was exporting was correct etc, however Beyond Compare does have the ability to be able to use command lines to compare. This then results in everything done programatically, all that has to be done is a user views the results in
Beyond Compare
. You may be able to export them to another CSV, I havn't looked as the GUI ofBeyond Compare
is very nice and useful, so it is easier to use this.