[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: possible gawk bug
From: |
Aharon Robbins |
Subject: |
Re: possible gawk bug |
Date: |
Tue, 17 Dec 2002 13:39:22 +0200 |
Greetings. Re this:
> Date: Tue, 17 Dec 2002 09:24:16 +0100
> From: Helge Skrivervik <address@hidden>
> To: address@hidden
> Subject: possible gawk bug
>
> the sub/gsub fundtion does not seem to be able to make the substitution
> of '&' to '\&', and I have come to the conclusion that this is most
> likely a bug. From the docs I would expect the correct syntax to be
> sub(/&/,"\\\&"), but while '\\' and '\&' alone work as substitutions,
> the combination does not. the gawk version is 3.1.1.(redhat 8)
>
> rgds,
> helge
$ echo 'escape me: & done' | gawk '{ sub(/&/, "\\\\&"); print }'
escape me: \& done
This general issue is discussed in the gawk doc. There are two levels
of processing: string scanning, and sub/gsub replacement. For string
scanning, gawk removes 1 level of backslash, thus sub sees the string
containing "\\&".
See node `Gory Details', which is section "More About \ and & with
sub, gsub, and gensub" in the printed doc.
Arnold
- possible gawk bug, Helge Skrivervik, 2002/12/17
- Re: possible gawk bug,
Aharon Robbins <=