[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] 0 is invalid as number of arguments for tolower
From: |
Stephane Chazelas |
Subject: |
Re: [bug-gawk] 0 is invalid as number of arguments for tolower |
Date: |
Sun, 11 Oct 2015 22:03:20 +0100 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
2015-10-11 20:16:04 +0200, Hermann Peifer:
>
> Hi again,
>
> I assume I am simply to naïve in assuming that the below would ever
> work. gsub() knows what `&' is about, but tolower() doesn't and will
> never learn, so this is a feature (and shouldn't be sent to bug-gawk
> in the first place ;-), correct?
>
> Hermann
>
> $ echo "LA SOMME, LA MANCHE, LE RHIN ET LA MER DU NORD" |
> awk 'gsub(/ (LE|LA|LES|ET|DU) /, tolower(&))'
> awk: cmd. line:1: gsub(/ (LE|LA|LES|ET|DU) /, tolower(&))
> awk: cmd. line:1: ^ syntax error
> awk: cmd. line:1: gsub(/ (LE|LA|LES|ET|DU) /, tolower(&))
> awk: cmd. line:1: ^ 0 is
> invalid as number of arguments for tolower
[...]
Yes.
Even if you did
awk 'gsub(/ (LE|LA|LES|ET|DU) /, tolower("&"))'
That would still be the same as:
awk 'gsub(/ (LE|LA|LES|ET|DU) /, "&")'
tolower("&") being "&".
Instead, you could do:
awk -v RS='LE|LA|LES|ET|DU' '{printf "%s", $0 tolower(RT)}'
With GNU sed:
sed -E 's/LE|LA|LES|ET|DU/\L&/g'
(a la vi). I suppose if gawk was to implement a similar feature,
it would do something similar.
--
Stephane