🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by Eric Gisin Fri, 10 May 1991 17:55
nawk sub/gsub bug
#407
Author: Eric Gisin
Date: Fri, 10 May 1991 17:55
14 lines
747 bytes
$ 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.
Re: nawk sub/gsub bug
#409
Author: 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 |
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads