两个文本文件之间的差异并保存到另一个文本文件 [英] Difference between two text files and save to another text file

查看:79
本文介绍了两个文本文件之间的差异并保存到另一个文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个不同的文件。

File1.txt包含: -



100

200

312

413

515



File2.txt包含



100

200

312

415

413

515

657



我想把两个文件的差异保存到另一个文件或打印不同之处。如何做到这一点。

解决方案

尽管问题的一些纯粹的幻想简单,两个文本文件之间的差异的概念令人惊讶地难以定义。例如,请参阅我过去的答案:

比较两个Xml文件 [ ^ ]。



参见:

如何比较两个文本文件并获得匹配百分比 [解决方案3 ],

如何比较两个文本文件并获得匹配百分比 [解决方案4 ]。



尽管如此,还有一类称为差异的方法,用于不同的应用程序,通常是版本控制系统,使用这些东西的一些实际有价值的定义。例如,在本文中查看此类算法的说明: http://en.wikipedia.org/wiki/Diff [ ^ ]。



另请参阅此比较列表: http://en.wikipedia.org/wiki/Comparison_of_file_comparison_tools [< a href =http://en.wikipedia.org/wiki/Comparison_of_file_comparison_toolstarget =_ blanktitle =New Window> ^ ]。



许多这些工具都是开源的,所以你可以很容易地弄清楚它们是如何工作的。



-SA

这里有很多方法: http:// www。 codeproject.com/script/Awards/View.aspx?cid=358 [ ^

I have two different files.
File1.txt contains:-

100
200
312
413
515

File2.txt contains

100
200
312
415
413
515
657

I want to take the differences of two files and save it to another file or print the differnces. How to do that.

解决方案

Despite of some purely illusionary simplicity of the problem, The concept of the "difference between two text files" is surprisingly difficult to define. See, for example, my past answer:
Comparison of Two Xml Files[^].

See also:
How to compare two text files and get the match percentage [Solution 3],
How to compare two text files and get the match percentage [Solution 4].

Nevertheless, there is a class of such methods called "differs", used in different applications, typically Revision Control Systems, which use some practically valuable definition of such things. Look, for example in this article with description of such algorithm: http://en.wikipedia.org/wiki/Diff[^].

See also this comparison list: http://en.wikipedia.org/wiki/Comparison_of_file_comparison_tools[^].

Many of these tools are open-source, so you can easily figure out how they work.

—SA


There are lots of ways over here: http://www.codeproject.com/script/Awards/View.aspx?cid=358[^]


这篇关于两个文本文件之间的差异并保存到另一个文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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