-b和-w差异


20

diff联机帮助页:

-b, --ignore-space-change
      ignore changes in the amount of white space

-w, --ignore-all-space
      ignore all white space

据此,我推断-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 
$

那么,-b-w选项之间有什么区别?在Kubuntu Linux 13.04上使用diffutils 3.2进行了测试。

Answers:


18

手册页在这一点上不是很清楚,但是信息页详细说明了:

1.2抑制空白和制表符间距的差异

--ignore-tab-expansion-E)选项忽略输入制表符和空格之间的区别。一个制表符被认为等于下一个制表符停止符的空格数(* note Tabs::)。

--ignore-trailing-space-Z)选项忽略在线路末端的空白。

--ignore-space-change-b)选项比强-E-Z合并。它忽略行尾的空白,并认为一行中一个或多个空白字符的所有其他序列是等效的。使用此选项,diff将以下两行视为等效,其中$表示行尾:

 Here lyeth  muche rychnesse  in lytell space.   -- John Heywood$
 Here lyeth muche rychnesse in lytell space. -- John Heywood   $

--ignore-all-space-w)选项是更加强大。即使一行中有空白而另一行中没有空白,它也会忽略差异。“空白”字符包括制表符,垂直制表符,换页符,回车符和空格;一些语言环境可能将其他字符定义为空格。使用此选项时,diff 认为以下两行是等效的,其中$表示行结束并^M表示回车:

 Here lyeth  muche  rychnesse in lytell space.--  John Heywood$
   He relyeth much erychnes  seinly tells pace.  --John Heywood   ^M$

对于许多其他程序,换行符也是空格字符,但它diff是面向行的程序,而换行符始终以一行结尾。因此,-wor --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 

-w的结果是什么。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.