当前位置: 动力学知识库 > 问答 > 编程问答 >

Change character that represents a newline for diff

问题描述:

I would like to be able to diff a file in a way that would split each new 'line' by '.' as opposed to '\n'

Is there any way to do this with the standard diff command?

My end goal of doing this is being able to do git diffs on plain text files that aren't filled with newlines.

网友答案:

Just use tr on the input files (and avoid a temporary file by using process substitution, a feature of bash):

diff -u <(tr . '\n' < file1) <(tr . '\n' < file2)

To integrate with git, you'll need to define a custom diff driver as per gitattributes(5), under Generating diff text

分享给朋友:
您可能感兴趣的文章:
随机阅读: