[Top][All Lists]

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

GNU grep, ".", newlines and -z

From: Richard Kettlewell
Subject: GNU grep, ".", newlines and -z
Date: Sun, 23 Jun 2002 22:53:58 +0100

According to the GNU Grep manual, under "Regular Expressions":

         The period `.' matches any single character.

However, if -z or --null-data are not used, then . does not match a

    lyonesse$ echo | ./grep .

This is expected behaviour, since grep isn't supposed to treat the
newline as part of the line; except in the GNU version there does
appear to be a newline character available to match against in this
context - at least if you ask for it explicitly:

    lyonesse$ echo | perl -e 'exec("./grep","\n");'


I think this is a bug.

When -z is used, the documentation is definitely correct and "." does
indeed match newlines:

    lyonesse$ perl -e 'print "\n\0";' | ./grep -z . | od -tx1
    0000000 0a 00

We spotted this in 2.4.2 but it still exists in 2.5.1.

I notice that

    By default, an input line shall be selected if any pattern,
    treated as an entire basic regular expression (BRE) [...] matches
    any part of the line excluding the terminating <newline>; a null
    BRE shall match every line.

V7 grep does not appear to include the terminating newline in the text
to match the pattern against.


reply via email to

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