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
--------------------------------------------------
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 ,-)
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
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!
Thanks to everyone! I update my gawk to v3.1.6, this bug has been
fixed. ^_^