nawk sub/gsub bug

Eric Gisin eric at mks.com
Sat May 11 03:55:55 AEST 1991


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



More information about the Comp.bugs.sys5 mailing list