bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gensub() matched component always empty, even for the exact text of


From: Ed Morton
Subject: Re: gensub() matched component always empty, even for the exact text of the example in the manual
Date: Sun, 3 Apr 2022 09:12:10 -0500
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0

It's unlikely that a bug like that could exist for all this time without hundreds/thousands of people reporting it. I don't have that gawk version any more but I don't see it in gawk 5.1.1 on cygwin:

   $ gawk --version | head -1
   GNU Awk 5.1.1, API: 3.1 (GNU MPFR 4.1.0, GNU MP 6.2.1)

   $ gawk '
   BEGIN {
         a = "abc def"
         b = gensub(/(.+) (.+)/, "\\2 \\1", "g", a)
         print b
   }'
   def abc

I suspect you copy/pasted the example wrong. Maybe you re-typed it instead of copying it and your editor used some other chars instead of the ASCII ones required?

Regards,

    Ed.


On 4/3/2022 8:29 AM, Zoli Márk via Bug reports only for gawk. wrote:
Hello -
I have run into a problem for which I needed the (g)awk function gensub(), namely the 
"identify matched components and reuse them in the replacement text" kind of 
problem. However, it seems that the component thus matched is always empty, and 
investigating the issue has shown that in this particular gawk not even the manual 
example works.
This happens on Ubuntu 20.04.
gawk -V replies "GNU Awk 5.0.1, API: 2.0 (GNU MPFR 4.0.2, GNU MP 6.2.0)" plus 
boilerplate. I can't tell anymore if I installed it from some repository or it came with 
Ubuntu - I am, however, sure that I did not install it from sources.
The manual I'm referring to is the one linked from thehttps://www.gnu.org/software/gawk/  page, namelyhttps://www.gnu.org/software/gawk/manual/gawk.html The example is the following:
$ gawk '
BEGIN {
      a = "abc def"
      b = gensub(/(.+) (.+)/, "\\2 \\1", "g", a)
      print b
}'
-| def abc
Instead of printing the promised "def abc", on my computer this code prints an 
empty line only, as both \\1 and \\2 are empty. (Actually it's not an empty line - it 
contains the space from between \\2 and \\1 in the replacement text, as it did with other 
characters in my code; only the matched components themselves are empty.) Is this a bug?
Best regards
        M- S- Z-




reply via email to

[Prev in Thread] Current Thread [Next in Thread]