dot*_*hen 22 linux diff command-line
从diff
联机帮助页:
-b, --ignore-space-change
ignore changes in the amount of white space
-w, --ignore-all-space
ignore all white space
Run Code Online (Sandbox Code Playgroud)
由此,我推断-b
和-w
选项之间的区别必须-b
是对空格类型(制表符与空格)敏感。然而,情况似乎并非如此:
$ diff 1.txt 2.txt
1,3c1,3
< Four spaces, changed to one tab
< Eight Spaces, changed to two tabs
< Four spaces, changed to two spaces
---
> Four spaces, changed to one tab
> Eight Spaces, changed to two tabs
> Four spaces, changed to two spaces
$ diff -b 1.txt 2.txt
$ diff -w 1.txt 2.txt
$
Run Code Online (Sandbox Code Playgroud)
那么,选项-b
和-w
选项有什么区别呢?在 Kubuntu Linux 13.04 上使用 diffutils 3.2 进行测试。
mpy*_*mpy 21
手册页在这一点上不是很清楚,但信息页详细说明:
1.2 抑制空白和制表符间距的差异
在
--ignore-tab-expansion
(-E
)选项忽略输入制表符和空格之间的区别。一个制表符被认为等同于到下一个制表位 (*note Tabs::) 的空格数。在
--ignore-trailing-space
(-Z
)选项忽略在线路末端的空白。在
--ignore-space-change
(-b
)选项比强-E
和-Z
合并。它忽略行尾的空格,并将一行中一个或多个空格字符的所有其他序列视为等效。使用此选项,diff
将以下两行视为等效,其中$
表示行结束:Run Code Online (Sandbox Code Playgroud)Here lyeth muche rychnesse in lytell space. -- John Heywood$ Here lyeth muche rychnesse in lytell space. -- John Heywood $
在
--ignore-all-space
(-w
)选项是更加强大。即使一行有空白而另一行没有空白,它也会忽略差异。“空格”字符包括制表符、垂直制表符、换页符、回车符和空格;某些语言环境可能会将附加字符定义为空格。使用此选项,diff
认为以下两行是等效的,其中$
表示行尾,^M
表示回车:Run Code Online (Sandbox Code Playgroud)Here lyeth muche rychnesse in lytell space.-- John Heywood$ He relyeth much erychnes seinly tells pace. --John Heywood ^M$
对于许多其他程序,换行符也是一个空白字符,但它
diff
是面向行的程序,换行符总是结束一行。因此-w
or--ignore-all-space
选项不会忽略与换行符相关的更改;它仅忽略其他空白更改。
小智 6
似乎单词之间的空格可能更多,但这是我的结果:
diff 1.txt 2.txt
1,2c1,2
< test
< next next
---
> te st
> next next
diff -b 1.txt 2.txt
1c1
< test
---
> te st
Run Code Online (Sandbox Code Playgroud)
-w 的结果是什么。