GNU bug report logs - #23185
GNU grep matching discrepancy between -a/--text and not.

Previous Next

Package: grep;

Reported by: Shlomi Fish <shlomif <at> shlomifish.org>

Date: Sat, 2 Apr 2016 12:06:01 UTC

Severity: normal

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

Bug is archived. No further changes may be made.

Full log


Message #10 received at 23185-done <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Shlomi Fish <shlomif <at> shlomifish.org>, 23185-done <at> debbugs.gnu.org
Subject: Re: bug#23185: GNU grep matching discrepancy between -a/--text and
 not.
Date: Tue, 5 Apr 2016 23:56:22 -0700
[Message part 1 (text/plain, inline)]
Thanks for pointing out the seeming inconsistency. The documentation mentions 
the issue but is perhaps not clear enough, so I installed the attached patch.

The input file contains NUL bytes and so is treated as binary data, and the grep 
documentation (secton "File and Directory Selection", option "--binary-files") 
says "When processing binary data, ‘grep’ may treat non-text bytes as line 
terminators". This behavior was added to GNU grep in release 2.21 dated 2014, 
partly for performance reasons.

There are two instances in riddle.he of a space followed by a NUL byte, so

  grep -P '[ \t]\r?$' riddles.he

finds a match when the $ matches just before the NUL byte.

-a is one way to get the behavior you evidently expected. Another (perhaps 
better) way is -z. The command:

  grep -zP '[ \t]\r?\n' riddles.he

outputs nothing and exits with status 1.
[0001-Give-another-example-of-binary-file-processing.patch (text/x-diff, attachment)]

This bug report was last modified 9 years and 132 days ago.

Previous Next


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