This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: OT: grep for \x00 = NUL


fergus wrote:

>         grep $'\x0d' # e.g. equivalent to grep "^M"

Using that method you're passing the literal character to grep through a
bash quoting mechanism.  You can't pass a literal NULL as part of a
command line because argv[] consists of NULL-delimited strings, as do
most C string functions.

Why not just tell grep to look for a NULL rather than trying to feed it
an actual literal NULL character?

$ grep -P '\000'

In pcre regexps you can use \nnn to match any character represented by
octal nnn.  This would work for any character, and it doesn't rely on a
bash-specific shell feature.  But it does rely on grep supporting -P for
pcre, which is not universal.  If that cannot be relied on then you can
use

$ perl -ne 'print if m/\000/'

or

$ awk '/\000/ { print }'

Brian

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]