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: Martin Schulte <gnu <at> schrader-schulte.de>
To: Philippe Cerfon <philcerf <at> gmail.com>
Cc: 71252 <at> debbugs.gnu.org
Subject: bug#71252: why does grep match literal newlines when there are none, even with -z?
Date: Wed, 29 May 2024 08:08:57 +0200
Hi!

> 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?

I was surprised at the first moment, too, but I think the answer is in first paragraph of the man page:

PATTERNS is one or more patterns separated by newline characters, and grep prints each line that matches a pattern.

Thus, grep $'a\nb' find all lines that either contain an a or a b.

Best regards

Martin




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.