bug-grep
[Top][All Lists]
Advanced

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

Re: bug report, grep not display the matched sting


From: Paolo Bonzini
Subject: Re: bug report, grep not display the matched sting
Date: Tue, 05 Mar 2013 23:56:20 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130219 Thunderbird/17.0.3

Il 01/03/2013 10:48, Quan Zhang ha scritto:
> system env:
> Fedora 18
> address@hidden grep-bug]$ grep -V
> 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>.
> 
> 
> desc:
> grep could not output matched string in some case
> 
> how to reproduce:
> 
>    1. put the attached files in a same dir
>    2. run the script x.sh
>    3. you will see the matched string
>    4. run the same command in the script ,it may be looks like this
>       - > cat tmp-a.tmp|grep --color=never Location|grep -Eo 'https.*'
>    5. you will see a blank line was output. and it should be the same with
>    running the script
> 
> thanks for any one of you who will fix this bug.

Interesting!

I suspect you have an alias like "alias grep='grep --color=auto'".

If so, the problem is due to the carriage-return at the end of the lines
of tmp-a.tmp.  By default, "grep --color" adds a "clear to end of line"
sequence at the end of each match.  The idea is to give the rest of the
line the correct background color, in case the match has a background
that is not black.

Unfortunately, the carriage-return moves the cursor back to the
beginning of the line, and the entire line is blanked.

It doesn't show with the script because the alias is not used.

The bug is that you should remove carriage-returns (for example with GNU
sed you can use "sed 's/\r$//'") before processing the output with POSIX
utilities.  POSIX utilities expect lines to be terminated by line-feed
characters.  HTTP and other Internet protocols use CR-LF pairs.

Paolo



reply via email to

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