This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: OT: grep for \x00 = NUL
- From: Brian Dessent <brian at dessent dot net>
- To: cygwin at cygwin dot com
- Date: Tue, 19 Jul 2005 09:45:06 -0700
- Subject: Re: OT: grep for \x00 = NUL
- References: <md5:2B2CF516B327FFCA0D2F3F274C35F083>
- Reply-to: cygwin at cygwin dot com
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/