awk character class mystery

It's a bug in mawk 1.3.3 and was reported here. You can upgrade to mawk 1.3.4 or use patch to fix the bug.

$ mawk -W version
mawk 1.3.4 20130219
Copyright 2013, Thomas E. Dickey
Copyright 1996, Michael D. Brennan

internal regex
compiled limits:
max NF             32767
sprintf buffer      2040

$ echo "host.company.com has address 192.168.22.82" | mawk '/^[[:alnum:].-]+ has address/ { print $4 }'
192.168.22.82

mawk uses extended regular expressions as with egrep, so it must support POSIX characters classes.


The documentation that you're referring to is of the GNU version of Awk, but the version you've is mawk (as shown by your first command) which is an awk variant that doesn't seem to support POSIX character classes like [:alpha:] or [:alnum:].

Edit: As mentioned by Gnouc, mawk does support POSIX character classes from version 1.3.4 onwards, so an update could fix your issue.

Tags:

Awk