Date: Sun, 3 Nov 2019 10:23:02 -0700 (MST) From: Dale Scott <dalescott@shaw.ca> To: Victor Sudakov <vas@sibptus.ru> Cc: freebsd-questions <freebsd-questions@freebsd.org> Subject: Re: grep for ascii nul Message-ID: <1183473267.187448543.1572801782450.JavaMail.zimbra@shaw.ca> In-Reply-To: <20191103164756.GA50239@admin.sibptus.ru> References: <20191101092716.GA67658@admin.sibptus.ru> <63808.1572638827@segfault.tristatelogic.com> <20191102064505.GA98558@admin.sibptus.ru> <7775e7f8-89ba-d057-67d3-cdcb92d2bbb4@panix.com> <20191103164756.GA50239@admin.sibptus.ru>
next in thread | previous in thread | raw e-mail | index | archive | help
There are ports for many GNU utilities, and BSD has a long history of staying pure to its roots (IMHO), so why not just install gnuawk and symlink awk to gnuawk? Cheers, Dale ----- Original Message ----- > From: "Victor Sudakov" <vas@sibptus.ru> > To: "freebsd-questions" <freebsd-questions@freebsd.org> > Sent: Sunday, November 3, 2019 9:47:56 AM > Subject: Re: grep for ascii nul > 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@fidonet http://vas.tomsk.ru/
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1183473267.187448543.1572801782450.JavaMail.zimbra>