Subject: bug#16979: Strange behavior with "grep --color=auto" with dot in expression

From: Paul Eggert <[email-masked]>
Date: Sun, 06 Apr 2014 12:50:18 -0700

This is due to the CR at the end of the line.  A simple way to reproduce 
the bug is:

printf 'X\r\n' | grep --color=always -E '(X|[[:space:]])'

This will output a line that appears to be empty.  If you filter the 
output of 'grep' through 'od -c', you'll see:

0000000 033   [   0   1   ;   3   1   m 033   [   K   X 033   [   m 033
0000020   [   K 033   [   0   1   ;   3   1   m 033   [   K  \r 033   [
0000040   m 033   [   K  \n

That is, begin color, erase to end of line, X, end color, erase to end 
of line, begin color, erase to end of line, carriage-return, end color, 
erase to end of line, linefeed.  The last "erase to end of line" erases 
the X.

As can be seen, the grep --color output is busted in this case, and is 
suboptimal in general.  Someone who cares about grep --color (which is 
not me :-) should take a look at it.

You can work around the bug by filtering out the CRs before running 
'grep', or by not using the --color option.