From owner-freebsd-questions@freebsd.org Sat Nov 2 06:45:14 2019 Return-Path: Delivered-To: freebsd-questions@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 33A6B166314 for ; Sat, 2 Nov 2019 06:45:14 +0000 (UTC) (envelope-from vas@sibptus.ru) Received: from admin.sibptus.ru (admin.sibptus.ru [IPv6:2001:19f0:5001:21dc::10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 474qLd2BDHz4HPR for ; Sat, 2 Nov 2019 06:45:12 +0000 (UTC) (envelope-from vas@sibptus.ru) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sibptus.ru; s=20181118; h=In-Reply-To:Message-ID:Subject:To:From:Date; bh=pRqprQdQAmLM+93wyxZl16S7G+gQ46MplLVUhGQJdMk=; b=hID8bOt/N+GCd2a9sF1JdyM/7h LqmKsDNlAE36XUTCeA5QIvi/pP2KCp6QnUf1IqAreEbhTOuXNQ0GT8DWplpEkPhCjh9pt9hNv5oLP nfQDUmT2xgB7U67Vn4n/6V1NUusaAK/R7XJGItYrcS58i4nMezn25ckDXWr2ECvl9e9k=; Received: from vas by admin.sibptus.ru with local (Exim 4.92.3 (FreeBSD)) (envelope-from ) id 1iQn9l-000PsO-HN for freebsd-questions@freebsd.org; Sat, 02 Nov 2019 13:45:05 +0700 Date: Sat, 2 Nov 2019 13:45:05 +0700 From: Victor Sudakov To: freebsd-questions@freebsd.org Subject: Re: grep for ascii nul Message-ID: <20191102064505.GA98558@admin.sibptus.ru> References: <20191101092716.GA67658@admin.sibptus.ru> <63808.1572638827@segfault.tristatelogic.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="/04w6evG8XlLl3ft" Content-Disposition: inline In-Reply-To: <63808.1572638827@segfault.tristatelogic.com> X-PGP-Key: http://admin.sibptus.ru/~vas/ X-PGP-Fingerprint: 10E3 1171 1273 E007 C2E9 3532 0DA4 F259 9B5E C634 User-Agent: Mutt/1.12.2 (2019-09-21) X-Rspamd-Queue-Id: 474qLd2BDHz4HPR X-Spamd-Bar: -------- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=sibptus.ru header.s=20181118 header.b=hID8bOt/; dmarc=pass (policy=none) header.from=sibptus.ru; spf=pass (mx1.freebsd.org: domain of vas@sibptus.ru designates 2001:19f0:5001:21dc::10 as permitted sender) smtp.mailfrom=vas@sibptus.ru X-Spamd-Result: default: False [-8.38 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; R_DKIM_ALLOW(-0.20)[sibptus.ru:s=20181118]; FROM_HAS_DN(0.00)[]; R_SPF_ALLOW(-0.20)[+mx]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.20)[multipart/signed,text/plain]; TO_DN_NONE(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; RCPT_COUNT_ONE(0.00)[1]; IP_SCORE(-3.28)[ip: (-9.84), ipnet: 2001:19f0:5000::/38(-4.92), asn: 20473(-1.57), country: US(-0.05)]; DKIM_TRACE(0.00)[sibptus.ru:+]; DMARC_POLICY_ALLOW(-0.50)[sibptus.ru,none]; SIGNED_PGP(-2.00)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+,1:+,2:~]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:20473, ipnet:2001:19f0:5000::/38, country:US]; RCVD_COUNT_TWO(0.00)[2] X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 02 Nov 2019 06:45:14 -0000 --/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 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--