逐行比较两个日志并显示差异以及行中单词的顺序是否相同

逐行比较两个日志并显示差异以及行中单词的顺序是否相同

我不需要工具,我需要实现/算法:)我需要制作一个 shellscript,因为我无法在服务器上安装任何东西

f2.txt

She has 123 apples
George 18 years is old
Florin it's leaving
Michael it's not here
Peter is smiling

f1.txt

She has 132 apples
George is 18 years old
Michael it's not here
Peter is smiling
He is sleeping

期望的输出:

diff is at:
line 1 : 123 instead of 132
line 2 : 18 years is instead of is 18 years
lines missing:
He is sleeping
lines added:
line 3: Florin it's leaving

答案1

不完全是您要求的格式,但wdiff可能是您最好的选择:

$ wdiff f1.txt f2.txt
She has [-132-] {+123+} apples
George [-is-] 18 years {+is+} old
{+Florin it's leaving+}
Michael it's not here
Peter is smiling
[-He is sleeping-]

相关内容