Diff

diff 報告兩個文件不同,儘管它們是相同的!

  • January 3, 2021

我有兩個看起來與我相同的文件(包括尾隨空格和換行符),但 diff 仍然表示它們不同。即使我進行diff -y並排比較,線條看起來也完全相同。diff 的輸出是整個 2 個文件。

知道是什麼原因造成的嗎?

奇怪..你能試試cmp嗎?您可能也想使用 ’ -b’ 選項。

cmp 手冊頁- 逐字節比較兩個文件。

這是 Unix/Linux 的優點之一 .. 這麼多工具 :)

嘗試:

diff file1 file2 | cat -t

-t選項將導致cat清楚地顯示任何特殊字元 - 例如。^M對於 CR,^I對於選項卡。

從手冊頁(OS X):

 -t      Display non-printing characters (see the -v option), and display tab characters as `^I'.

 -v      Display non-printing characters so they are visible.
         Control characters print as `^X' for control-X; the delete character
         (octal 0177) prints as `^?'.  Non-ASCII characters
         (with the high bit set) are printed as `M-' (for meta) followed by the
         character for the low 7 bits.

引用自:https://unix.stackexchange.com/questions/45711