nawk sub/gsub bug

Arnold Robbins arnold at audiofax.com
Tue May 14 04:47:21 AEST 1991


In article <1991May10.175555.10306 at mks.com> eric at 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 at audiofax.com  Phone:   +1 404 618 4281 |     -- Rob Pike
UUCP:	  emory!audfax!arnold  Fax-box: +1 404 618 4581 |



More information about the Comp.bugs.sys5 mailing list