From unknown Fri Aug 15 21:26:19 2025 X-Loop: help-debbugs@gnu.org Subject: bug#16979: Strange behavior with "grep --color=auto" with dot in expression Resent-From: Peter Maloney Original-Sender: "Debbugs-submit" Resent-CC: bug-grep@gnu.org Resent-Date: Mon, 10 Mar 2014 15:47:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 16979 X-GNU-PR-Package: grep X-GNU-PR-Keywords: To: 16979@debbugs.gnu.org X-Debbugs-Original-To: bug-grep@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.13944663954735 (code B ref -1); Mon, 10 Mar 2014 15:47:02 +0000 Received: (at submit) by debbugs.gnu.org; 10 Mar 2014 15:46:35 +0000 Received: from localhost ([127.0.0.1]:60467 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WN2PR-0001EI-VJ for submit@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 ) id 1WMxRH-0005xG-QO for submit@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 ) id 1WMxRB-0002sx-M2 for submit@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 ) id 1WMxRB-0002st-HU for submit@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 ) id 1WMxR6-00080T-6o for bug-grep@gnu.org; Mon, 10 Mar 2014 06:28:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WMxR0-0002rY-Ru for bug-grep@gnu.org; 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 ) id 1WMxR0-0002r7-JI for bug-grep@gnu.org; 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@brockmann-consult.de> Date: Mon, 10 Mar 2014 11:27:42 +0100 From: Peter Maloney User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 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-Mailman-Approved-At: Mon, 10 Mar 2014 11:46:33 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" 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 . 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 . $ 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 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@brockmann-consult.de Internet: http://www.brockmann-consult.de -------------------------------------------- From unknown Fri Aug 15 21:26:19 2025 X-Loop: help-debbugs@gnu.org Subject: bug#16979: Strange behavior with "grep --color=auto" with dot in expression References: <531D939E.4010202@brockmann-consult.de> In-Reply-To: <531D939E.4010202@brockmann-consult.de> Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-CC: bug-grep@gnu.org Resent-Date: Sun, 06 Apr 2014 19:51:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 16979 X-GNU-PR-Package: grep X-GNU-PR-Keywords: To: 16979@debbugs.gnu.org Received: via spool by 16979-submit@debbugs.gnu.org id=B16979.139681383215121 (code B ref 16979); Sun, 06 Apr 2014 19:51:01 +0000 Received: (at 16979) by debbugs.gnu.org; 6 Apr 2014 19:50:32 +0000 Received: from localhost ([127.0.0.1]:38384 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WWt5L-0003vo-VB for submit@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 ) id 1WWt5J-0003vb-6H for 16979@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@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@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@debbugs.gnu.org>; Sun, 6 Apr 2014 12:50:19 -0700 (PDT) Message-ID: <5341AFFA.1090804@cs.ucla.edu> Date: Sun, 06 Apr 2014 12:50:18 -0700 From: Paul Eggert 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 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -2.6 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" 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.