How to enable interval regular expression in mawk?

无人久伴 提交于 2019-12-23 02:52:53

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!