Apparently, a bracket expression in BSD Awk which contains a character class will ignore any further characters after the character class:
MacOS $ cat file.txt
_
-
.
a
B
8
:
;
@
~
,
MacOS $ awk '/[@~.[:alnum:]:;-]/' file.txt
.
a
B
8
@
~
MacOS $ awk '/[-;:@~.[:alnum:]]/' file.txt
-
.
a
B
8
:
;
@
~
MacOS $ awk '/[^@~.[:alnum:]:;-]/' file.txt
_
-
:
;
,
MacOS $ awk '/[^-;:@~.[:alnum:]]/' file.txt
_
,
MacOS $
On GNU Awk (shown on Ubuntu 16.04), the behavior is different; other characters in the bracket expression are handled the same regardless of whether they come before or after the character class:
Linux $ cat file.txt
_
-
.
a
B
8
:
;
@
~
,
Linux $ awk '/[@~.[:alnum:]:;-]/' file.txt
-
.
a
B
8
:
;
@
~
Linux $ awk '/[-;:@~.[:alnum:]]/' file.txt
-
.
a
B
8
:
;
@
~
Linux $ awk '/[^@~.[:alnum:]:;-]/' file.txt
_
,
Linux $ awk '/[^-;:@~.[:alnum:]]/' file.txt
_
,
Linux $
Is this documented anywhere? Or, if it is a bug, is it a known bug? (And if it is a known bug, is it fixed in later versions of Awk?)
What should I do with this discovery? Is there somewhere I should open a bug report?
LANG=C awk ...
versusLANG=xx.UTF-8
.awk
,mawk
andgawk
are consistent in their behaviour on OpenBSD and does the right things.echo 'foo:bar: info' | awk '/^[:[:alpha:]]+: /'
outputsfoo:bar: info
as expected whileecho 'foo:bar: info' | awk '/^[[:alpha:]:]+: /'
outputs nothing unless I prefix it withLANG=C
.awk --version
outputsawk version 20070501
. GNU awk produces the expected output regardless of the order inside the bracket expression.