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

The special regexp operator /\B/ can't work as expected

0 views
Skip to first unread message

redraiment

unread,
Jan 4, 2010, 9:07:43 AM1/4/10
to
My GNU awk's version is 3.1.5, the special regexp operator '\B' can't
work as expected.

The document from "The GNU Awk User's Guide"
--------------------------------------------------
\B
Matches the empty string that occurs between two word-constituent
characters. For example, /\Brat\B/ matches ‘crate’ but it does not
match ‘dirty rat’. ‘\B’ is essentially the opposite of ‘\y’.
--------------------------------------------------

It's my data file:
--------------------------------------------------
ABCDE
ABCD
ABC
AB
A
--------------------------------------------------

replaces all /\B/ with gsub:
--------------------------------------------------
$ awk '{gsub(/\B/,"X")}1' data
AXBXCXDE
AXBXCD
AXBC
AXB
A
--------------------------------------------------

And, the expected result is:
--------------------------------------------------
$ awk '{gsub(/\B/,"X")}1' data
AXBXCXDXE
AXBXCXD
AXBXC
AXB
A
--------------------------------------------------

Loki Harfagr

unread,
Jan 4, 2010, 10:34:17 AM1/4/10
to
Mon, 04 Jan 2010 06:07:43 -0800, redraiment did cat :

Er... Why would it be your expected result?

Please try with this input file, close to man page:
-------------------
$ cat tyty
ABrateDE
ArateCD
ArateC
Arate
A
-------------------

And check with this test, close to man page:
-------------------
$ awk '{gsub(/\Brat\B/,"X")}1' /dev/shm/tyty
ABXeDE
AXeCD
AXeC
AXe
A
-------------------

now, re-read your original post ,-)

Radoulov, Dimitre

unread,
Jan 4, 2010, 10:49:50 AM1/4/10
to
On 04/01/2010 16.34, Loki Harfagr wrote:
> Mon, 04 Jan 2010 06:07:43 -0800, redraiment did cat :
>
>> My GNU awk's version is 3.1.5, the special regexp operator '\B' can't
>> work as expected.
[...]
[...]


I get a different output with GNU Awk 3.1.7 though:


% awk 'gsub(/\B/,"X")' data
AXBXCXDXE
AXBXCXD
AXBXC
AXB

... and using GNU Awk 3.1.5 I get this:


$ awk 'gsub(/\B/,"X")' data
AXBXCXDE
AXBXCD
AXBC
AXB

Regards
Dimitre

Loki Harfagr

unread,
Jan 4, 2010, 1:41:51 PM1/4/10
to
Mon, 04 Jan 2010 16:49:50 +0100, Radoulov, Dimitre did cat :

This is interesting, with 3.1.6 I get the same result you and OP got with 3.1.5,
which result is, in my understanding of the 'man gawk' and/or 'gawk UG', correct
as the end of line is, to me, akin to "empty-string".
Now, only the gawk maintainer will be able to tell if it is a regression in
3.1.7 or if I simply incorrectly understood the concept (which I admit
is quite misty in many aspects ;-) ?
And, my apologies to the OP if I got it all wrong!

redraiment

unread,
Jan 4, 2010, 10:41:50 PM1/4/10
to
On Jan 5, 2:41 am, Loki Harfagr <l...@thedarkdesign.free.fr.INVALID>

Thanks to everyone! I update my gawk to v3.1.6, this bug has been
fixed. ^_^

0 new messages