--line-regexp option with null data
Fri Jul 17 11:55:00 GMT 2015
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
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 604 bytes
Desc: OpenPGP digital signature
More information about the Cygwin