[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gensub() matched component always empty, even for the exact text of the
From: |
Zoli Márk |
Subject: |
gensub() matched component always empty, even for the exact text of the example in the manual |
Date: |
Sun, 3 Apr 2022 13:29:50 +0000 (UTC) |
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 the
https://www.gnu.org/software/gawk/ page, namely
https://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-