Newsgroups: comp.bugs.sys5
Path: utzoo!utgpu!watserv1!watmath!mks.com!eric
From: eric@mks.com (Eric Gisin)
Subject: nawk sub/gsub bug
Organization: Mortice Kern Systems Inc., Waterloo, Ontario, CANADA
Date: Fri, 10 May 91 17:55:55 GMT
Message-ID: <1991May10.175555.10306@mks.com>

$ 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.
