GNU bug report logs - #32704
Can grep search for a line feed and a null character at the same time?

Previous Next

Package: grep;

Reported by: 21naown <at> gmail.com

Date: Tue, 11 Sep 2018 16:27:01 UTC

Severity: wishlist

Full log


Message #23 received at 32704 <at> debbugs.gnu.org (full text, mbox):

From: 21naown <at> gmail.com
To: 32704 <at> debbugs.gnu.org, Eric Blake <eblake <at> redhat.com>,
 Paul Eggert <eggert <at> cs.ucla.edu>
Subject: Re: bug#32704: Can grep search for a line feed and a null character
 at the same time?
Date: Sat, 15 Sep 2018 19:57:24 +0200
Le 15/09/2018 à 19:06, Eric Blake a écrit :
> On 9/15/18 11:43 AM, 21naown <at> gmail.com wrote:
>> Thank you for your messages.
>>
>> It is possible I did not understand correctly your messages, because 
>> grep finds hex sequences with the “-Pa” options at least.
>
> grep -P introduces a completely different regex engine, with its own 
> quirks.  As such, it does introduce different rules on backslash 
> sequences accepted.
>
>>
>> Examples—“input.txt” contains, from the file system, for example 
>> “\xFF\xFE\x0D\x00\x0A\x00\x74\x00\x65\x00\x73\x00\x74\x00\x0D\x00\x0A\x00\x74\x00\x65\x00\x73\x00\x74\x00\x5F\x00\x74\x00\x77\x00\x6F\x00\x0D\x00\x0A\x00”: 
>>
>> grep -Pa '\x00' input.txt
>> → found
>> grep -Pza '\x0A' input.txt
>> → found
>> grep -Pa '\x0A\x00' input.txt
>
> This will never match - when you are not using -z, there are no \x0A 
> in the input stream (they have all been consumed by grep parsing one 
> line at a time, ending at \x0A).  Instead, you'll want to search for 
> '^\x00' or '\x00$' for a pattern anchored to a line transition, to 
> find patterns where newline was next to NUL.
>
>> grep -Pza '\x0A\x00' input.txt
>> → not found for the both
>
> Similarly, when you are using -z, there are no \x00 in the input 
> stream (they  have all been consumed by grep parsing one 
> NUL-terminated record at a time, ending at \x00).  Instead, you'll 
> want to search for '^\x0a' or '\x0a$' for a pattern anchored to a 
> record transition, to find patterns where newline was next to NUL.
>
>>
>> But is it at least possible to find “\x0A\x00” with grep?
>
> If you bend the rules by throwing -P into the mix, yes :)
>
So it is possible to find “\x0A\x00” alone, but for example 
“\x74\x00\x0D\x00\x0A\x00\x74\x00\x65\00” is impossible to find with the 
“-P” option?




This bug report was last modified 4 years and 329 days ago.

Previous Next


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