Diff -b e -w diferença

12

Na% man_de% manpage:

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

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

A partir disso, deduzo que a diferença entre as opções diff e -b deve ser que -w é sensível ao tipo de espaços em branco (tabulações x espaços). No entanto, isso não parece ser o caso:

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

Então, qual é a diferença entre as opções -b e -b ? Testado com o diffutils 3.2 no Kubuntu Linux 13.04.

    
por dotancohen 29.06.2013 / 16:15

2 respostas

13

A página de manual não é muito clara nesse ponto, mas a página de informações é elaborada:

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.

    
por 29.06.2013 / 16:39
6

Parece que há espaços entre palavras, talvez mais, mas este é o meu resultado:

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 

resultados de -w não são nada.

    
por 29.06.2013 / 16:41