GNU bug report logs - #16979
Strange behavior with "grep --color=auto" with dot in expression

Previous Next

Package: grep;

Reported by: Peter Maloney <peter.maloney <at> brockmann-consult.de>

Date: Mon, 10 Mar 2014 15:47:02 UTC

Severity: normal

To reply to this bug, email your comments to 16979 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-grep <at> gnu.org:
bug#16979; Package grep. (Mon, 10 Mar 2014 15:47:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Peter Maloney <peter.maloney <at> brockmann-consult.de>:
New bug report received and forwarded. Copy sent to bug-grep <at> gnu.org. (Mon, 10 Mar 2014 15:47:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Peter Maloney <peter.maloney <at> brockmann-consult.de>
To: bug-grep <at> gnu.org
Subject: Strange behavior with "grep --color=auto" with dot in expression
Date: Mon, 10 Mar 2014 11:27:42 +0100
Strange behavior with "grep --color=auto" with dot in expression

For some reason, ssh produces output with CRLF when there is a key
problem, and when I redirected that to a file, and used grep to search
through it, I found that it seemed like "." was not matching correctly,
but when you pipe the output to "cat", it looks as expected. And without
"--color=auto" or with unix line endings, it works fine.



$ alias grep
alias grep='grep --color=auto'
$ diff <(hexdump -C file.txt) <(hexdump -C file2.txt)
4,5c4,5
< 00000030  41 53 54 59 21 0d 0a                              |ASTY!..|
< 00000037
---
> 00000030  41 53 54 59 21 0a                                 |ASTY!.|
> 00000036
$ grep -i nasty file2.txt | grep .
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
$ grep -i nasty file.txt | grep .

$ grep -i nasty file.txt | grep . | cat
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!

$ file file*
file2.txt: ASCII text
file.txt:  ASCII text, with CRLF line terminators


I tested it in konsole and xterm, and both do the same, so I guess you
just need:

$ grep --version
grep (GNU grep) 2.14
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and others, see
<http://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.

$ bash --version
GNU bash, version 4.2.45(1)-release (x86_64-suse-linux-gnu)
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

-- 

--------------------------------------------
Peter Maloney
Brockmann Consult
Max-Planck-Str. 2
21502 Geesthacht
Germany
Tel: +49 4152 889 300
Fax: +49 4152 889 333
E-mail: peter.maloney <at> brockmann-consult.de
Internet: http://www.brockmann-consult.de
--------------------------------------------





Information forwarded to bug-grep <at> gnu.org:
bug#16979; Package grep. (Sun, 06 Apr 2014 19:51:01 GMT) Full text and rfc822 format available.

Message #8 received at 16979 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: 16979 <at> debbugs.gnu.org
Subject: Re: Strange behavior with "grep --color=auto" with dot in expression
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.




This bug report was last modified 10 years and 13 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.