grep for ascii nul
Victor Sudakov
vas at sibptus.ru
Sun Nov 3 16:48:05 UTC 2019
Kurt Hackenberg wrote:
>
> > 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
> > $
>
> Looks like it has the same problem that I guess grep does: it takes that
> NUL as the end of a C string, so the regexp becomes a null string (zero
> length), which matches everything.
You know what, lang/gawk does not have this problem:
$ gawk '/\x00/{print $0}' trees.txt
cedar
$
This is not the first time BSD AWK sucks in comparison with GNU AWK :-(
Do you think this is worth a PR?
--
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/20191103/56d9cdd6/attachment.sig>
More information about the freebsd-questions
mailing list