免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1701 | 回复: 4
打印 上一主题 下一主题

求助匹配模式n至m次的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-01-30 14:08 |只看该作者 |倒序浏览
如下,第二个awk输出为空,原意是想数值匹配1至3次

sbmp:/tmp/ou # awk '{if($1~/[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/) print $1}' /etc/hosts
127.0.0.1
127.0.0.2
10.69.18.213
192.168.1.113

sbmp:/tmp/ou #  awk '{if($1~/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/) print $1}' /etc/hosts

论坛徽章:
0
2 [报告]
发表于 2010-01-30 14:47 |只看该作者
awk  --re-interval '$1 ~ /[0-9]{1,3}\.[0-9]......./'

论坛徽章:
0
3 [报告]
发表于 2010-01-30 17:59 |只看该作者
请教我写的那个有什么问题呢

论坛徽章:
0
4 [报告]
发表于 2010-01-30 19:41 |只看该作者

回复 #3 qinghan1125 的帖子

man awk

--re-interval
              Enable the use of interval expressions in regular expression matching (see Regular , Expressionsbelow).  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.

论坛徽章:
0
5 [报告]
发表于 2010-01-30 20:36 |只看该作者

回复 #3 qinghan1125 的帖子

其实主要是AWK的版本问题在 POSIX之前的版本大括号不可使用。 之后就可以 了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP