bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Paul Eggert
Subject: bug#16979: Strange behavior with "grep --color=auto" with dot in expression
Date: Sun, 06 Apr 2014 12:50:18 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0

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.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]