From owner-freebsd-questions@freebsd.org Fri Nov 1 20:07:09 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 97CE11A18C0 for ; Fri, 1 Nov 2019 20:07:09 +0000 (UTC) (envelope-from rfg@tristatelogic.com) Received: from outgoing.tristatelogic.com (segfault.tristatelogic.com [69.62.255.118]) by mx1.freebsd.org (Postfix) with ESMTP id 474YBN4MVbz3CQv for ; Fri, 1 Nov 2019 20:07:08 +0000 (UTC) (envelope-from rfg@tristatelogic.com) Received: by segfault.tristatelogic.com (Postfix, from userid 1237) id 2DDCD4E684; Fri, 1 Nov 2019 13:07:07 -0700 (PDT) From: "Ronald F. Guilmette" To: Victor Sudakov cc: freebsd-questions@freebsd.org Subject: Re: grep for ascii nul In-Reply-To: <20191101092716.GA67658@admin.sibptus.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <63807.1572638826.1@segfault.tristatelogic.com> Date: Fri, 01 Nov 2019 13:07:07 -0700 Message-ID: <63808.1572638827@segfault.tristatelogic.com> X-Rspamd-Queue-Id: 474YBN4MVbz3CQv X-Spamd-Bar: ----- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of rfg@tristatelogic.com designates 69.62.255.118 as permitted sender) smtp.mailfrom=rfg@tristatelogic.com X-Spamd-Result: default: False [-5.16 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+mx]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[tristatelogic.com]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; RCVD_COUNT_ZERO(0.00)[0]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:14051, ipnet:69.62.128.0/17, country:US]; IP_SCORE(-2.86)[ip: (-7.50), ipnet: 69.62.128.0/17(-3.75), asn: 14051(-2.98), country: US(-0.05)] 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: Fri, 01 Nov 2019 20:07:09 -0000 In message <20191101092716.GA67658@admin.sibptus.ru>, Victor Sudakov wrote: >I need to find files containing ascii null inside, and print their names to > stdout. 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. I would thus suggest that you solve your problem using a Perl or C program. It would be relatively easy to code up a solution to your stated problem in either of these two languages. Something approximately like this might work. (But I DO NOT guarrantee that this will work. If you want guarrantees, send money.) You would give this script a list of the filenames you wanted checked on the command line when you invoke it. =========================================================================== #!/usr/local/bin/perl -w use strict; undef $/; foreach my $arg (@ARGV) { open (IFILE, "; close (IFILE) || die; print "$arg\n" if ($content ~= m/\000/); }