🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.bugs.sys5
Article #409

Re: nawk sub/gsub bug

#409
From: Arnold Robbins
Date: Mon, 13 May 1991 18:47
28 lines
1571 bytes
In article <1991May10.175555.10306@mks.com> eric@mks.com (Eric Gisin) writes:
|$ uname -r
|3.2
|$ echo .xx. | sed 's/xx*/\\&\\/'
|.\xx\.
|# note that "\\" passes a single \ to sub.
|$ echo .xx. | nawk '{sub(/x+/,"\\&\\"; print}'
|.&\.
|$ echo .xx. | nawk '{sub(/x+/,"\\\\&\\\\"; print}'
|.\&\\.
|
|I don't know whether its a feature or a bug, but you can't use sub
|to enclose a substring with \'s, as the sed example does.
|The sub/gsub algorithm should be modified to replace \& with &,
|\\ with \, and leave all other escapes alone.

The bug, if such, is in the original design of awk.  sub and gsub weren't
intended to be as general purpose as the 's' command in ed(1).  Your
dismay is understandable, but I think this one of those things that are
too late to fix.

Because of this, we're considering an edsub(string, pat, rep, globalflag)
function for a future version of gawk....
-- 
Arnold Robbins				 AudioFAX, Inc. | Threads are the
2000 Powers Ferry Road, Suite 200 / Marietta, GA. 30067 | lack of an idea.
INTERNET: arnold@audiofax.com  Phone:   +1 404 618 4281 |     -- Rob Pike
UUCP:	  emory!audfax!arnold  Fax-box: +1 404 618 4581 |
Technical Details
Message-ID: <371@audfax.audiofax.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!swrinde!emory!audfax!arnold
References: <1991May10.175555.10306@mks.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!swrinde!emory!audfax!arnold
From: arnold@audiofax.com (Arnold Robbins)
Newsgroups: comp.bugs.sys5
Subject: Re: nawk sub/gsub bug
Message-ID: <371@audfax.audiofax.com>
Date: 13 May 91 18:47:21 GMT
References: <1991May10.175555.10306@mks.com>
Organization: AudioFAX, Inc., Atlanta Georgia
Lines: 28