[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] gawk 4.1.3 gensub() warning
From: |
Stephane Chazelas |
Subject: |
Re: [bug-gawk] gawk 4.1.3 gensub() warning |
Date: |
Thu, 3 Sep 2015 14:22:53 +0100 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
2015-09-03 06:34:42 -0600, address@hidden:
> Ed Morton <address@hidden> wrote:
>
> > I'm seeing this new warning in gawk 4.1.3 executing existing scripts:
> >
> > $ echo 'a' | gawk '{print gensub(/a/,"b","")}'
> > gawk: cmd. line:1: (FILENAME=- FNR=1) warning: gensub: third argument `'
> > treated
> > as 1
> > b
> >
> > This will impact a ton of scripts, like if sed suddenly started issuing
> > warnings
> > if you wrote `s/foo/bar/` instead of `s/foo/bar/1`. Is it here to stay?
> >
> > Ed.
>
> The warning is indeed here to stay. Use of "" is wrong; you should
> supply a numeric 1 there. Fix your scripts.
[...]
I can confirm that the use of gensub(/x/, repl, "") is
widespread.
On unix.stackexchange.com for instance, at a quick glance, a
large proportion of the answers involving a non-"g" gensub
(https://unix.stackexchange.com/search?q=gensub) have "" instead
of 1.
A few examples:
https://unix.stackexchange.com/questions/170606/extracting-trace-information-using-gawk/212892#212892
https://unix.stackexchange.com/questions/216544/how-to-print-a-line-if-that-line-or-the-next-line-do-not-contain-a-particular-st/216581#216581
https://unix.stackexchange.com/questions/72425/awk-gensub-function/72432#72432
https://unix.stackexchange.com/questions/23174/increment-number-in-bash-variable-string/23176#23176
https://unix.stackexchange.com/questions/183883/how-to-highlight-given-string-in-given-place/188450#188450
https://unix.stackexchange.com/questions/182400/print-ip-address-with-interface-name/182471#182471
https://unix.stackexchange.com/questions/205540/append-something-to-each-list-in-a-file/205584#205584
A search on usenet comp.lang.awk
(https://groups.google.com/forum/#!searchin/comp.lang.awk/gensub)
seems to bring a few as well
Though the behaviour for "" is undocumented, that's what easily
comes to mind if you translate a sed/ed s/x/y/ command to awk.
So I can easily imagine this change causing some annoyance.
--
Stephane