使用'diff'(或任何其他)获得文本文件之间的字符级别差异 [英] Using 'diff' (or anything else) to get character-level diff between text files

查看:203
本文介绍了使用'diff'(或任何其他)获得文本文件之间的字符级别差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用'diff'来获得两行之间的差异和字符差异。
例如,考虑:



文件1

  abcde 
abc
abcccd

文件2

  abcde 
ab
abccc

使用 diff -u 我会得到:

  @@ -1,3 +1,3 @@ 
abcde
-abc
-abcccd
\否在文件末尾有换行符
+ ab
+ abccc
\文件末尾没有换行符

但是,它只显示我是这些行中的更改。我想看到的是:

  @@ -1,3 +1,3 @@ 
abcde
-ab< ins> c< / ins>
-abccc< ins> d< / ins>
\文件末尾没有换行符
+ ab
+ abccc
\文件末尾没有换行符


现在,我知道我可以使用

/code.google.com/p/google-diff-match-patch/rel =nofollow noreferrer>其他引擎来标记/检查特定行上的差异。

解决方案

我没有检查python库,但最终找到了 Google 的解决方案足以满足我的需求。它实现在许多语言(其中的C#)。我印象深刻。


I'd like to use 'diff' to get a both line difference between and character difference. For example, consider:

File 1

abcde
abc
abcccd

File 2

abcde
ab
abccc

Using diff -u I get:

@@ -1,3 +1,3 @@
 abcde
-abc
-abcccd
\ No newline at end of file
+ab
+abccc
\ No newline at end of file

However, it only shows me that were changes in these lines. What I'd like to see is something like:

@@ -1,3 +1,3 @@
 abcde
-ab<ins>c</ins>
-abccc<ins>d</ins>
\ No newline at end of file
+ab
+abccc
\ No newline at end of file

You get my drift.

Now, I know I can use other engines to mark/check the difference on a specific line. But I'd rather use one tool that does all of it.

解决方案

I didn't check the python library but eventually found Google's solution good enough for what I needed. And it is implemented in so many languages (C# among them). I was impressed.

这篇关于使用'diff'(或任何其他)获得文本文件之间的字符级别差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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