Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 2 Nov 2019 13:45:05 +0700
From:      Victor Sudakov <vas@sibptus.ru>
To:        freebsd-questions@freebsd.org
Subject:   Re: grep for ascii nul
Message-ID:  <20191102064505.GA98558@admin.sibptus.ru>
In-Reply-To: <63808.1572638827@segfault.tristatelogic.com>
References:  <20191101092716.GA67658@admin.sibptus.ru> <63808.1572638827@segfault.tristatelogic.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--/04w6evG8XlLl3ft
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Ronald F. Guilmette wrote:
> In message <20191101092716.GA67658@admin.sibptus.ru>,=20
> Victor Sudakov <vas@sibptus.ru> wrote:
>=20
> >I need to find files containing ascii null inside, and print their names=
 to
> > stdout.
>=20
> Unfortunately, you're banging up against a long-standing a rather
> annoying non-feature of fgrep/grep/egrep, which is that unlike the
> tr command, the grep family of commands does not support the \DDD
> notation for specifying arbitrary byte values.  Thus, you cannot use
> then to search for arbitrary byte values.
>=20
> I would thus suggest that you solve your problem using a Perl or C
> program. =20

Perl is not in the base system, so that is not quite the answer.=20
I'm a big fan of awk, awk is in the base system and should be able to do
it, right?

$ hd trees.txt=20
00000000  66 69 72 0a 6f 61 6b 0a  63 65 64 00 61 72 0a 62  |fir.oak.ced.ar=
=2Eb|
00000010  69 72 63 68 0a 70 61 6c  6d 0a                    |irch.palm.|
0000001a
$=20

Note the ascii null embedded in the word "cedar"

$ awk '/\x66\x69/{print $0}' trees.txt
fir

So far so good. But with the ascii nul it behaves in an unexpected way:

$ awk '/\x00/{print $0}' trees.txt
fir
oak
ced
birch
palm
$=20


--=20
Victor Sudakov,  VAS4-RIPE, VAS47-RIPN
2:5005/49@fidonet http://vas.tomsk.ru/

--/04w6evG8XlLl3ft
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iQEcBAEBAgAGBQJdvSXxAAoJEA2k8lmbXsY0qWwH/RkTNDcpCPx62KmkBx99CG6V
NiohEjWgP0ZNpna6EKwHLKhO6ZV+zi9rBJbTS9u/Rwx8oH9NQnCVbhhHV9s5bzjq
hnwajl7WeAp6b2KpfG1kMoVS68vUUJ/sSIa5VFmVX/gBu+6e+RqRHsM21IoW/UJA
hqgr5sPCL/9nYo7EeMi0UkZxsnkYQXGcvsSCGk6Cabk15eA669A1qdqzlz/LBBdp
oJdAHOFrlKaO1xrHaUFRJlCIUmbe8ObhY1UY0hPFCRThlExvVOl2L4A6ei/Nfatj
DXW9sVLHuMR922CbIE1pzeQQt7d1iJKZbqzOCFrRA21Ko7EdLV6+eGEgrSP3AHA=
=afP5
-----END PGP SIGNATURE-----

--/04w6evG8XlLl3ft--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20191102064505.GA98558>