From owner-freebsd-questions@freebsd.org Sun Nov 3 17:23:07 2019 Return-Path: Delivered-To: freebsd-questions@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id BE85F17C99B for ; Sun, 3 Nov 2019 17:23:07 +0000 (UTC) (envelope-from dalescott@shaw.ca) Received: from smtp-out-no.shaw.ca (smtp-out-no.shaw.ca [64.59.134.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "Client", Issuer "CA" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 475jSB3wtzz4Xk3 for ; Sun, 3 Nov 2019 17:23:06 +0000 (UTC) (envelope-from dalescott@shaw.ca) Received: from cds220.dcs.int.inet ([10.0.153.144]) by shaw.ca with ESMTP id RJagijAbvnCigRJahiR6UY; Sun, 03 Nov 2019 10:23:04 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shaw.ca; s=s20180605; t=1572801784; bh=CCiVTcZ98iXaTadXjjsNxiyTpVkoPVeXCN01R94zLaA=; h=Date:From:To:Cc:In-Reply-To:References:Subject; b=FWD+oJ1bOao1wb09sYpC0W4gGacoQHBduS1FNKdBtdBtvIEJP6YpFqE0XoyyhfRjW 3pWsZkyQ5YCumu32i8YfwZhzzWFSG1aeGNsHK4d9Dki13g99n4JHZW1NFm7FIUe+I8 dx1/QTtEeo0Zw7rAzLVoYRjigRmlQUbDOZ4xNlpSRStfJ7hwiAEFy1xLlqip12HXNV B7iFsANi6m9QJmOg78Ph/2fJ+BR13F21BQNc46/LqcoWgPxDt0iU28qnhG/pHnlyWk /VEM+NaU7nAc1CSJPRqPLtVdg+3dK+bp0BExr6hgIAfxJfk9/gw9zkbNW/cQDKOqVG 77bES3LfsBWxA== X-Authority-Analysis: v=2.3 cv=cZisUULM c=1 sm=1 tr=0 a=YjOmSjUxhsfmstj0eziGpw==:117 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=FKkrIqjQGGEA:10 a=RDteU5_PNoYA:10 a=IkcTkHD0fZMA:10 a=cbhV4p7HAAAA:8 a=6I5d2MoRAAAA:8 a=d9DUfOFSAAAA:8 a=vGc2HjyRYsAT2bcu-58A:9 a=QEXdDO2ut3YA:10 a=z-V2QqvRhG52jeeRkh-B:22 a=IjZwj45LgO3ly-622nXo:22 a=GsQOLwZiQaHj5U2p_RK9:22 Date: Sun, 3 Nov 2019 10:23:02 -0700 (MST) From: Dale Scott To: Victor Sudakov Cc: freebsd-questions 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> Subject: Re: grep for ascii nul MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [174.0.43.39, 174.0.43.39] X-Mailer: Zimbra 8.8.11_GA_3799 (ZimbraWebClient - GC77 (Linux)/8.8.11_GA_3787) Thread-Topic: grep for ascii nul Thread-Index: mrVc7WMjRYOhQCEE++hDh+vNPx0EHQ== X-CMAE-Envelope: MS4wfO8azGAHr/xTupofxInQllt3PnpNOiIzHfHiq/eHMSq/70EmS84ysWVydi0qaBDb76ybxz803BYOJhYYV4v5M91hmpk2XiksEiQRqvLEQ14iC3GPIerg TR/ytD4NMMWaidl7oh2Bga8+BKE3chGIU8b0Y3fsjWoSP9mLdZ3XLLCas6qoAKXjMcnM9E4unBLF+5RNjXUMW+I6vLtyi1U2Bug= X-Rspamd-Queue-Id: 475jSB3wtzz4Xk3 X-Spamd-Bar: ----- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=shaw.ca header.s=s20180605 header.b=FWD+oJ1b; dmarc=pass (policy=none) header.from=shaw.ca; spf=pass (mx1.freebsd.org: domain of dalescott@shaw.ca designates 64.59.134.9 as permitted sender) smtp.mailfrom=dalescott@shaw.ca X-Spamd-Result: default: False [-5.33 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; R_DKIM_ALLOW(-0.20)[shaw.ca:s=s20180605]; HAS_XOIP(0.00)[]; FROM_HAS_DN(0.00)[]; DWL_DNSWL_NONE(0.00)[shaw.ca.dwl.dnswl.org : 127.0.5.0]; R_SPF_ALLOW(-0.20)[+ip4:64.59.134.0/25]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[text/plain]; IP_SCORE(-2.33)[ip: (-6.19), ipnet: 64.59.128.0/20(-3.02), asn: 6327(-2.33), country: CA(-0.09)]; TO_MATCH_ENVRCPT_SOME(0.00)[]; TO_DN_ALL(0.00)[]; DKIM_TRACE(0.00)[shaw.ca:+]; RCPT_COUNT_TWO(0.00)[2]; RCVD_IN_DNSWL_NONE(0.00)[9.134.59.64.list.dnswl.org : 127.0.5.0]; DMARC_POLICY_ALLOW(-0.50)[shaw.ca,none]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:6327, ipnet:64.59.128.0/20, country:CA]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_COUNT_TWO(0.00)[2] X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 Nov 2019 17:23:07 -0000 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" > To: "freebsd-questions" > 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/