grep for ascii nul
Victor Sudakov
vas at sibptus.ru
Sat Nov 2 06:45:14 UTC 2019
Ronald F. Guilmette wrote:
> In message <20191101092716.GA67658 at admin.sibptus.ru>,
> Victor Sudakov <vas at 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.
Perl is not in the base system, so that is not quite the answer.
I'm a big fan of awk, awk is in the base system and should be able to do
it, right?
$ hd trees.txt
00000000 66 69 72 0a 6f 61 6b 0a 63 65 64 00 61 72 0a 62 |fir.oak.ced.ar.b|
00000010 69 72 63 68 0a 70 61 6c 6d 0a |irch.palm.|
0000001a
$
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
$
--
Victor Sudakov, VAS4-RIPE, VAS47-RIPN
2:5005/49 at fidonet http://vas.tomsk.ru/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 455 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20191102/4979b2e8/attachment.sig>
More information about the freebsd-questions
mailing list