比较两个CSV文件 [英] Compare two CSV file

查看:116
本文介绍了比较两个CSV文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个C#中的代码,它比较两个CSV文件,并保存第三个CSV文件中不匹配的列号和数据。

CSV可以有1万行和30列。

I need a code in C# which compare two CSV file and saving the not matched column number and data in 3rd CSV file.
CSV can have 1 lakh rows and 30 columns.

推荐答案

写一个(可能很快) CSV 解析器并完成工作。

看看在此代码项目文章:快速CSV阅读器 [ ^ ]。
Write a (possibly fast) CSV parser and do the job.
Have a look at this Code Project article: "A Fast CSV Reader"[^].


假设您要比较的CSV文件具有相同的列名称,那么如果您有权访问SQL Server,SQL Server express会这样做,那么我建议导入将每个CSV文件放入单独的表中(使用T SQLBULK INSERT)并使用SQL查询来标识哪些行具有不匹配的列。您可以使用查询输出生成(例如,从数据集中)您的输出CSV文件。



Lakh(100,000?)SQL中的行比较 可能 比你自己写的任何东西都快。



有关如何获得的一些提示,请参阅解决方案1以获取以下问题从代码中将CSV文件导入SQL Server。 *警告*如果你决定尝试这种方法,你需要为你的问题稍微修改一下。



SQL程序插入 [ ^ ]



如果您可以通过SQL Server Manager(或本周所谓的任何内容)访问SQL Server DB,这不是一个过程需要自动化然后有(或曾经是)一个向导,它将指导您导入CSV文件。
Assuming your CSV files to be compared have the same column "names" then if you have access to SQL Server, SQL server express would do, then I'd suggest importing each CSV file into separate tables (use T SQL "BULK INSERT") and using SQL queries to identify which rows have columns that don't match. You can use the query output to generate (e.g. from a dataset) your output CSV file.

Lakh (100,000?) row comparisons in SQL are likely to be faster than anything you can write yourself.

See solution 1 for the following question for a few hints on how to import CSV files into SQL server from code. *Warning* you'll need to modify it a bit for your problem if you do decide to try this approach.

SQL Procedure with insert[^]

If you've got access to SQL server DBs via SQL Server Manager (or whatever it's called this week) and this is not a procedure that needs automating then there is (or used to be) a wizard that will guide you through importing a CSV file.


这篇关于比较两个CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆