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

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: grep; Reported by: Peter Maloney <peter.maloney@HIDDEN>; dated Mon, 10 Mar 2014 15:47:02 UTC; Maintainer for grep is bug-grep@HIDDEN.

Message received at 16979 <at> debbugs.gnu.org:


Received: (at 16979) by debbugs.gnu.org; 6 Apr 2014 19:50:32 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Apr 06 15:50:32 2014
Received: from localhost ([127.0.0.1]:38384 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1WWt5L-0003vo-VB
	for submit <at> debbugs.gnu.org; Sun, 06 Apr 2014 15:50:32 -0400
Received: from smtp.cs.ucla.edu ([131.179.128.62]:40677)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <eggert@HIDDEN>) id 1WWt5J-0003vb-6H
 for 16979 <at> debbugs.gnu.org; Sun, 06 Apr 2014 15:50:29 -0400
Received: from localhost (localhost.localdomain [127.0.0.1])
 by smtp.cs.ucla.edu (Postfix) with ESMTP id D314F39E8018
 for <16979 <at> debbugs.gnu.org>; Sun,  6 Apr 2014 12:50:27 -0700 (PDT)
X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu
Received: from smtp.cs.ucla.edu ([127.0.0.1])
 by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id nH+oLGLlqw9e for <16979 <at> debbugs.gnu.org>;
 Sun,  6 Apr 2014 12:50:19 -0700 (PDT)
Received: from [192.168.1.9] (pool-108-0-233-62.lsanca.fios.verizon.net
 [108.0.233.62])
 by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 4F86839E8013
 for <16979 <at> debbugs.gnu.org>; Sun,  6 Apr 2014 12:50:19 -0700 (PDT)
Message-ID: <5341AFFA.1090804@HIDDEN>
Date: Sun, 06 Apr 2014 12:50:18 -0700
From: Paul Eggert <eggert@HIDDEN>
Organization: UCLA Computer Science Department
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
 rv:24.0) Gecko/20100101 Thunderbird/24.4.0
MIME-Version: 1.0
To: 16979 <at> debbugs.gnu.org
Subject: Re: Strange behavior with "grep --color=auto" with dot in expression
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Spam-Score: -2.6 (--)
X-Debbugs-Envelope-To: 16979
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <http://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.6 (--)

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.




Information forwarded to bug-grep@HIDDEN:
bug#16979; Package grep. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 10 Mar 2014 15:46:35 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Mar 10 11:46:35 2014
Received: from localhost ([127.0.0.1]:60467 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1WN2PR-0001EI-VJ
	for submit <at> debbugs.gnu.org; Mon, 10 Mar 2014 11:46:34 -0400
Received: from eggs.gnu.org ([208.118.235.92]:41113)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <peter.maloney@HIDDEN>)
 id 1WMxRH-0005xG-QO
 for submit <at> debbugs.gnu.org; Mon, 10 Mar 2014 06:28:08 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <peter.maloney@HIDDEN>)
 id 1WMxRB-0002sx-M2
 for submit <at> debbugs.gnu.org; Mon, 10 Mar 2014 06:28:07 -0400
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled
 version=3.3.2
Received: from lists.gnu.org ([2001:4830:134:3::11]:42215)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <peter.maloney@HIDDEN>)
 id 1WMxRB-0002st-HU
 for submit <at> debbugs.gnu.org; Mon, 10 Mar 2014 06:28:01 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:42825)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <peter.maloney@HIDDEN>)
 id 1WMxR6-00080T-6o
 for bug-grep@HIDDEN; Mon, 10 Mar 2014 06:28:01 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <peter.maloney@HIDDEN>)
 id 1WMxR0-0002rY-Ru
 for bug-grep@HIDDEN; Mon, 10 Mar 2014 06:27:56 -0400
Received: from moutng.kundenserver.de ([212.227.126.187]:59418)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <peter.maloney@HIDDEN>)
 id 1WMxR0-0002r7-JI
 for bug-grep@HIDDEN; Mon, 10 Mar 2014 06:27:50 -0400
Received: from [10.3.0.26] ([141.4.215.32])
 by mrelayeu.kundenserver.de (node=mreue003) with ESMTP (Nemesis)
 id 0MURVP-1WnjNf3DDX-00RGm5; Mon, 10 Mar 2014 11:27:48 +0100
Message-ID: <531D939E.4010202@HIDDEN>
Date: Mon, 10 Mar 2014 11:27:42 +0100
From: Peter Maloney <peter.maloney@HIDDEN>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
 rv:24.0) Gecko/20100101 Thunderbird/24.3.0
MIME-Version: 1.0
To: bug-grep@HIDDEN
Subject: Strange behavior with "grep --color=auto" with dot in expression
X-Enigmail-Version: 1.5.2
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Provags-ID: V02:K0:+nKeRDf6EFnAljA5NFCXMk+YpQayR1hWD+TmIUEjDT4
 NxtXsOe+UfZwoYl4AyElj70tdJ9ZeX6VPqtii6EdJC72l5qlcf
 4hbnKjBmkLtwDnSvIJUvv1ERhOz3ZAt9YouGvcEQDJpJF3XXXk
 Fe9W4ClxZw+6/lTjPoq5XUbCkLOQ8Yqoy11isxtOZejCSEby7m
 33LXc/qDf/EoC5oOER5IdJOKHXlO+w9qrv2wWY4IdMhfNm+nK/
 vleavVXvmTyEOr+n9LoRE1gAtYhZIk3nSjBYyBaYtHG//xPQ+n
 2B1oaTL7SbvhK090OOTNNy2XQM+G/zKuEEM/j7qUjgRvnWINpG
 llOZJvZM5PlNh3mdVhhebAp3G68xOZRB7M86zAykn
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic]
X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address
 (bad octet value).
X-Received-From: 2001:4830:134:3::11
X-Spam-Score: -5.0 (-----)
X-Debbugs-Envelope-To: submit
X-Mailman-Approved-At: Mon, 10 Mar 2014 11:46:33 -0400
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <http://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -5.0 (-----)

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@HIDDEN
Internet: http://www.brockmann-consult.de
--------------------------------------------





Acknowledgement sent to Peter Maloney <peter.maloney@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-grep@HIDDEN. Full text available.
Report forwarded to bug-grep@HIDDEN:
bug#16979; Package grep. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Mon, 25 Nov 2019 12:00:02 UTC

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