2 つのファイルの比較は典型的な問題であり、この問題については多くの議論があることを知っています。しかし、テキスト ファイルの操作中にはかなり別の問題があります。行数が異なる 2 つのテキスト ファイルがあります。ここで、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などのツールが役立つことはわかっていますが、その結果をこの形式に変換するにはどうすればよいですか?
前もって感謝します。