Date: Sat, 2 Nov 2019 14:57:14 -0400 From: Kurt Hackenberg <kh@panix.com> To: freebsd-questions@freebsd.org Subject: Re: grep for ascii nul Message-ID: <7775e7f8-89ba-d057-67d3-cdcb92d2bbb4@panix.com> In-Reply-To: <20191102064505.GA98558@admin.sibptus.ru> References: <20191101092716.GA67658@admin.sibptus.ru> <63808.1572638827@segfault.tristatelogic.com> <20191102064505.GA98558@admin.sibptus.ru>
next in thread | previous in thread | raw e-mail | index | archive | help
On 2019-11-02 02:45, Victor Sudakov 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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?7775e7f8-89ba-d057-67d3-cdcb92d2bbb4>