Date: Fri, 01 Nov 2019 13:07:07 -0700 From: "Ronald F. Guilmette" <rfg@tristatelogic.com> To: Victor Sudakov <vas@sibptus.ru> Cc: freebsd-questions@freebsd.org Subject: Re: grep for ascii nul Message-ID: <63808.1572638827@segfault.tristatelogic.com> In-Reply-To: <20191101092716.GA67658@admin.sibptus.ru>
next in thread | previous in thread | raw e-mail | index | archive | help
In message <20191101092716.GA67658@admin.sibptus.ru>, Victor Sudakov <vas@sibptus.ru> 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, "<arg") || die; my $content = <IFILE>; close (IFILE) || die; print "$arg\n" if ($content ~= m/\000/); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?63808.1572638827>