Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I seem to be unable to use a character class for an awk regular expression, almost exactly as described here :

user@host:~$ awk -W version
mawk 1.3.3 Nov 1996, Copyright (C) Michael D. Brennan

compiled limits:
max NF             32767
sprintf buffer      2040
user@host:~$ echo "host.company.com has address" |awk '/^[a-zA-Z0-9.-]+ has address/ { print $4 }'
user@host:~$ echo "host.company.com has address" |awk '/^[[:alnum:].-]+ has address/ { print $4 }'

Does anyone see why the second command fails to find the address field?

share|improve this question
up vote 5 down vote accepted

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" | mawk '/^[[:alnum:].-]+ has address/ { print $4 }'

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

share|improve this answer

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.

share|improve this answer
No, mawk suppport POSIX characters classes. See my answer. – cuonglm Aug 7 '14 at 18:17
In the manual from the link you posted, it says it supports Posix 1003.2 (draft 11.3) and is based on the 1988 Aho, Kernighan and Weinberger awk book... – Survenant Lazurite Aug 7 '14 at 18:27
You're right. The links that I referred to for my answer were quite old during which there was no support for POSIX character classes. – Chirag64 Aug 7 '14 at 18:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.