Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

From the diff manpage:

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

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

From this, I infer that the difference between the -b and -w options must be that -b is sensitive to the type of whitespace (tabs vs. spaces). However, that does not seem to be the case:

$ 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 
$

So, what is the difference between the -b and -w options? Tested with diffutils 3.2 on Kubuntu Linux 13.04.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

The man page isn't very clear on that point, but the info page elaborates:

1.2 Suppressing Differences in Blank and Tab Spacing

The --ignore-tab-expansion (-E) option ignores the distinction between tabs and spaces on input. A tab is considered to be equivalent to the number of spaces to the next tab stop (*note Tabs::).

The --ignore-trailing-space (-Z) option ignores white space at line end.

The --ignore-space-change (-b) option is stronger than -E and -Z combined. It ignores white space at line end, and considers all other sequences of one or more white space characters within a line to be equivalent. With this option, diff considers the following two lines to be equivalent, where $ denotes the line end:

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

The --ignore-all-space (-w) option is stronger still. It ignores differences even if one line has white space where the other line has none. "White space" characters include tab, vertical tab, form feed, carriage return, and space; some locales may define additional characters to be white space. With this option, diff considers the following two lines to be equivalent, where $ denotes the line end and ^M denotes a carriage return:

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

For many other programs newline is also a white space character, but diff is a line-oriented program and a newline character always ends a line. Hence the -w or --ignore-all-space option does not ignore newline-related changes; it ignores only other white space changes.

share|improve this answer

Seems like it is spaces between words maybe more but this is my result:

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 

results from -w is nothing.

share|improve this answer
    
+1; this is a nice example. –  mpy Jun 29 '13 at 14:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.