比较文件时如何忽略行尾? [英] How can I ignore line endings when comparing files?
本文介绍了比较文件时如何忽略行尾?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在比较两个文本文件,得到以下结果:
I am comparing two text files and I get the following result:
diff file1 file2 | grep 12345678
> 12345678
< 12345678
如您所见,两个文件中都存在相同的字符串,并且两个文件都用 sort
。
As you can see, the same string exists in both files, and both files were sorted with sort
.
这里的行尾必定会造成麻烦(Windows与Unix)。
The line endings must be getting in the way here (Windows vs. Unix).
是有没有办法让 diff
忽略Unix上的行尾?
Is there a way to get diff
to ignore line endings on Unix?
推荐答案
使用-strip-trailing-cr
选项:
diff --strip-trailing-cr file1 file2
该选项导致 diff
剥离在比较文件之前,尾随回车符。
The option causes diff
to strip the trailing carriage return character before comparing the files.
这篇关于比较文件时如何忽略行尾?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文