gpt4 book ai didi

regex - awk 和 regex 的简单问题

转载 作者:行者123 更新时间:2023-12-04 17:26:29 25 4
gpt4 key购买 nike

 echo xx y11y rrr | awk '{ if ($2 ~/y[1-5]{2}y/) print $3}'

为什么我无法获得任何输出?

谢谢你。

最佳答案

您需要通过指定 --posix 在正则表达式匹配中启用“间隔表达式”。或 --re-interval选项。

例如

echo xx y11y rrr | awk --re-interval '{ if ($2 ~ /y[1-5]{2}y/) print $3}

从手册页:

--re-interval Enable the use of interval expressions in regular expression matching (see Regular Expressions, below). Interval expressions were not traditionally available in the AWK language. The POSIX standard added them, to make awk and egrep consistent with each other. However, their use is likely to break old AWK programs, so gawk only provides them if they are requested with this option, or when --posix is specified.

关于regex - awk 和 regex 的简单问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8343058/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com