Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

No escape needed for period with gensub

28 views
Skip to first unread message

Robert Mesibov

unread,
Aug 4, 2016, 4:32:40 AM8/4/16
to
With gawk 4.1.1, a period character doesn't need escaping to make it literal:

$ echo "a . b" | awk '{print gensub(/ . /,".",$0)}'
a.b

A period is listed as a metacharacter in the GNU AWK manual, so why doesn't it need to be escaped?

Kenny McCormack

unread,
Aug 4, 2016, 4:49:44 AM8/4/16
to
In article <43b584a7-409b-413c...@googlegroups.com>,
Two comments:
1) Your 3rd parameter to gensub() is wrong. It should be 1.

2) Your assumption is wrong. Your reg exp / . / matches a space
followed by any character followed by another space. This 3
character sequence occurs just once in "a . b".

$ echo "a X b" | gawk '{print gensub(/ . /,".",1)}'
a.b
$

--
I'm building a wall.

Robert Mesibov

unread,
Aug 4, 2016, 5:06:34 AM8/4/16
to
On Thursday, August 4, 2016 at 6:49:44 PM UTC+10, Kenny McCormack wrote:
> Two comments:
> 1) Your 3rd parameter to gensub() is wrong. It should be 1.

Oops. My mistake, the demo was hastily built from a longer non-demo command.
>
> 2) Your assumption is wrong. Your reg exp / . / matches a space
> followed by any character followed by another space. This 3
> character sequence occurs just once in "a . b".
>
Many thanks, I hadn't thought of it that way.
0 new messages