How to ignore line endings when comparing files?

依然范特西╮ 提交于 2019-12-18 10:36:00

问题


I am comparing two text files and I get the following result

diff file1 file2 | grep 12345678

> 12345678
< 12345678

As you can see the same string exists in both files, and both files were sorted with sort.

The line endings must be getting in the way here (windows vs unix).

Is there a way to get diff to ignore line endings on unix?


回答1:


Use the --strip-trailing-cr option:

diff --strip-trailing-cr file1 file2

the option causes diff to strip the trailing carriage return character before comparing the files.



来源:https://stackoverflow.com/questions/40974170/how-to-ignore-line-endings-when-comparing-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!