Subject: Re: bug#25513: Issue grepping lines ending with CRLF with --color=auto.

From: Jim Meyering <[email-masked]>
Date: Mon, 23 Jan 2017 09:12:44 -0800

tags 25513 notabug
thanks

On Mon, Jan 23, 2017 at 8:03 AM, Eric Hoffman
<[email-masked]> wrote:
> grep is behaving differently when outputting with --color=auto when lines are ending with CRLF (like Windows text files).
>
> The issue is that if I have a file with CRLF line terminator, for example, a file named test.txt, containing:
> Line 1<CR><LF>
> Line 2<CR><LF>
> Line 3<CR><LF>
>
> Or:
>
> $od -c test.txt
> 0000000   L   i   n   e       1  \r  \n   L   i   n   e       2  \r  \n
> 0000020   L   i   n   e       3  \r  \n
> 0000030
>
> Then, If I type:
> $ grep --color=auto "." test.txt
...

Thank you for the report. I too see that behavior, but it is not a
problem with grep. It is due to the way carriage returns are rendered.
Here, even without --color, you can see that the three matched line
render as empty:

$ printf 'line%s\r\n' 1 2 3 | grep .

However, if you pipe that result through cat -A, you see that grep is
working as required:

$ printf 'line%s\r\n' 1 2 3 | grep .|cat -A
line1^M$
line2^M$
line3^M$

So I'm closing this bug.