关于awk和regx简单烦恼 [英] simple trouble about awk and regx

查看:96
本文介绍了关于awk和regx简单烦恼的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

为什么我不能得到一些输出?
领先的THX。

why I cannot get some output? Thx ahead.

推荐答案

您需要通过指定,使常规的前pression匹配的间隔前pressions无论是 - POSIX - 重新间隔选项

You need to enable "interval expressions" in regular expression matching by specifying either the --posix or --re-interval option.

例如

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

从手册页:

- 重新间隔
         在启用前常规pression匹配使用间隔前pressions的(请参见正防爆pressions,下同)。间隔前pressions人
  在传统上不使用
         在AWK语言。 POSIX标准的补充他们,使awk和egrep命令彼此一致。然而,它们的使用是
  有可能打破旧的AWK程序,所以,
         呆子只提供他们,如果他们被要求使用该选项,或指定时--posix。

--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.

这篇关于关于awk和regx简单烦恼的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆