Awk – Bounds in Awk Regular Expression Do Not Work on OpenBSD

awkopenbsdregular expression

This awk expression prints inet 34.45 as expected on OpenBSD:

echo "inet 34.45" | awk '/inet [0-9]+\./ { print }'

However, when I replace the + with a bound {1,3}, I am not getting any match:

echo "inet 34.45" | awk '/inet [0-9]{1,3}\./ { print }'

Both expressions work as expected on Linux with gawk. The gawk man page mentions that what it calls interval expressions were not originally supported by awk but later added to POSIX for consistency with egrep. The awk man page on OpenBSD mentions no such thing and just refers to the man page of re_format, which specifies bounds as usual.

Is this a bug or some undocumented limitation of OpenBSD awk?

Best Answer

That restriction is precisely documented.

From: http://man.openbsd.org/awk.1#STANDARDS

STANDARDS

The awk utility is compliant with the IEEE Std 1003.1-2008 (“POSIX.1”) specification, except awk does not support {n,m} pattern matching.

Related Question