我知道比较 2 个文件是一个典型的问题,关于这个问题有很多讨论。但是在处理文本文件时我遇到了一个完全不同的问题:我有两个文本文件,它们的行数可能不同。现在我想比较两个文件并找到不同的行。之后,我想标记两个文件中的所有差异。例如这里是我的文件的内容:
文件 1.txt:
This is the first line.
This line is just appeared in File1.txt.
you can see this line in both files.
this line is also appeared in both files.
this line and,
this one are mereged in File2.txt.
文件2.txt:
This is the first line.
you can see this line in both files.
this line is also appeared in both files.
this line and, this one are mereged in File2.txt.
处理后我希望这两个文件都是这样的:
文件 1.txt:
This is the first line.
<Diff>This line is just appeared in File1.txt.</Diff>
you can see this line in both files.
this line is also appeared in both files.
<Diff>this line and,</Diff>
<Diff>this one are merged in File2.txt.</Diff>
文件2.txt:
This is the first line.
<Diff></Diff>
you can see this line in both files.
this line is also appeared in both files.
<Diff>this line and, this one are mereged in File2.txt.</Diff>
<Diff></Diff>
我怎样才能做到这一点?我知道diff之类的一些工具可以帮助我,但是我怎样才能将它们的结果转换为这种格式呢?
先感谢您。