Ignore newlines with diff

巧了我就是萌 提交于 2019-12-04 18:40:12

问题


I'd like to ignore newlines when I compare c source files. For example I want following two codes are reported they are same.

// codeA
int main(int argc, char *argv[]) 
{

// codeB
int main(int argc, char *argv[]) {

I already have tried following options but could not get the result.

diff -b codeA codeB
diff -w codeA codeB

回答1:


You can pretty print both files using, for example, GNU Indent, http://www.gnu.org/software/indent/ , and then compare them with diff.




回答2:


There is a tool called "word diff" (tool command line must be 'wdiff') which might help. http://www.gnu.org/software/wdiff/manual/wdiff.html




回答3:


If you want an all or nothing answer you can first strip the files of newlines:

cat file.txt | tr -d '\n' > stripped.txt 

This is of course very unhelpful for finding actual differences.



来源:https://stackoverflow.com/questions/13192890/ignore-newlines-with-diff

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