该-w标志的手段:
-w --ignore-all-space
Ignore all white space.
Run Code Online (Sandbox Code Playgroud)
现在,这不是很清楚,因为“空白”实际上\n通常包括在内。例如,\sPerl Compatible Regular Expressions 或 POSIX 中的类[[:space:]]都匹配换行符:
$ printf '\n' | grep -zqP '\s' && echo yes
yes
$ printf '\n' | grep -zq '[[:space:]]' && echo yes
yes
Run Code Online (Sandbox Code Playgroud)
但是,diff通过比较行和行是由\n字符定义的(grep实际上也是如此,这就是我必须在-z上面使用的原因)。因此,diff不能\n考虑因为\n意味着这是一条不同的线路。所以不,该-w选项不会导致diff丢弃换行符,空行表示文件不匹配:
$ printf 'foo\nbar\n' > file1
$ printf 'foo\n\nbar\n' > file2
$ diff -wq file1 file2
Files file1 and file2 differ
Run Code Online (Sandbox Code Playgroud)
但是,diff由于行数,有一个选项确实可以忽略更改:
-B --ignore-blank-lines
Ignore changes whose lines are all blank.
$ diff -sB file1 file2
Files file1 and file2 are identical
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
759 次 |
| 最近记录: |