public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: cygwin@cygwin.com
Subject: Re: --line-regexp option with null data
Date: Fri, 17 Jul 2015 11:55:00 -0000	[thread overview]
Message-ID: <55A8ED20.8050509@redhat.com> (raw)
In-Reply-To: <6138-1437098652-808922@sneakemail.com>

[-- Attachment #1: Type: text/plain, Size: 1357 bytes --]

On 07/16/2015 08:04 PM, John Hein wrote:

>  >     printf 'alpha\0bravo\0charlie\0' | grep --line-regexp --quiet bravo
>  >
>  > My thinking tells me that because I have not used `--null-data`, grep should see
>  > 1 or even 0 lines separated by newline, and fail to match a `bravo` followed by
>  > newline. However it does not, it succeeds just like the first command, why is
>  > this?
>  >
>  > Note I also tried this on Debian with Grep 2.2 and it works as expected.
>  >
>  > http://stackoverflow.com/q/31467045
> 
> cygwin grep is detecting the input as binary which seems to be
> overriding the 'match the whole line' behavior of --line-regexp.  Get
> rid of --quiet to see that.

The behavior on Linux is the same.  See the NEWS for grep 2.21:

  When searching binary data, grep now may treat non-text bytes as
  line terminators.  This can boost performance significantly.

> 
> That does seem like a bug in the cygwin implementation of grep to me.

No, it is intentional upstream behavior.

> 
> As a workaround for this simple example, you can add -a (aka --text)
> to force it to treat the input as text.

Yes, that IS the correct solution.  You must TELL grep to not treat \0
as a line terminator.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

      parent reply	other threads:[~2015-07-17 11:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-17  1:29 Steven Penny
2015-07-17  2:04 ` John Hein
2015-07-17  2:35   ` Andrey Repin
2015-07-17  3:04     ` Steven Penny
2015-07-17  3:26       ` Vince Rice
2015-07-17  3:44   ` Steven Penny
2015-07-17 11:55   ` Eric Blake [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55A8ED20.8050509@redhat.com \
    --to=eblake@redhat.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).