GNU bug report logs - #71252
why does grep match literal newlines when there are none, even with -z?

Previous Next

Package: grep;

Reported by: Philippe Cerfon <philcerf <at> gmail.com>

Date: Wed, 29 May 2024 01:04:02 UTC

Severity: normal

Tags: notabug

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: "David G. Pickett" <dgpickett <at> aol.com>
To: "71252 <at> debbugs.gnu.org" <71252 <at> debbugs.gnu.org>,  Philippe Cerfon <philcerf <at> gmail.com>
Subject: bug#71252: why does grep match literal newlines when there are none, even with -z?
Date: Thu, 30 May 2024 02:33:37 +0000 (UTC)
[Message part 1 (text/plain, inline)]
I have used sed to load multiple lines into the buffer for analysis.  I am not sure grep wants to go multiline.




 

    On Tuesday, May 28, 2024 at 09:04:20 PM EDT, Philippe Cerfon <philcerf <at> gmail.com> wrote:   

 Hey.

I always thought, that grep is line based in a way that the current
string doesn't hold the line terminator.
If so, why does, e.g.:
  $ printf 'foo' | grep $'\n'
  foo
match?

Even with -z.
While:
  $ printf 'foo\nbar' | grep -z $'\n'
  foo
  bar
would make sense to me, why does it also match:
  $ printf 'foobar' | grep -z $'\n'
  foobar
?


In PCRE mode:
  $ printf 'foobar' | grep -P -z '\n'
  $
No match, that I would expect.
  $ printf 'foo\nbar' | grep -P -z '\n'
  foo
  bar
Match, again, expected.
But:
  $ printf 'foobar' | grep -P -z $'\n'
  foobar
Why does that match?

Thanks,
Philippe



  
[Message part 2 (text/html, inline)]

This bug report was last modified 1 year and 59 days ago.

Previous Next


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