问题
I hit an issue when I run the mawk on Ubuntu 1604:
echo "123-456" | mawk '$0~/^[0-9]{3}/ {print $0}'
The above command output nothing although the regular pattern matched actually.
Then I tried to run the egrep with the same regular pattern:
echo "123-456" | egrep '^[0-9]{3}'
It works fine!
Then I looked up the doc of the mawk, it seems the root cause is "Interval expressions were not traditionally available in awk.". The field "{3}" in the regular pattern cause the issue. If I use "[0-9][0-9][0-9]" instead of "[0-9]{3}": , it works fine.
https://invisible-island.net/mawk/manpage/mawk.html
https://www.math.utah.edu/docs/info/gawk_5.html
I tried the option --posix' and
--re-interval' for the mawk, they don't work both.
Is it possible that can enable the "Interval expressions" in the mawk? My OS is "Ubuntu 16.04.4", the mawk is "1.3.3-17ubuntu2".
Thanks.
来源:https://stackoverflow.com/questions/51061467/how-to-enable-interval-regular-expression-in-mawk