免费注册 查看新帖 |

Chinaunix

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

grep -w 的怪异问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-06-21 19:26 |只看该作者 |倒序浏览
文件中有  test.txt
10.10.10.10   node-1-priv
10.10.10.10   node-1
10.10.10.10   node-1_priv


为什么我用grep -w node-1 test.txt的查询结果是
10.10.10.10   node-1-priv
10.10.10.10   node-1


不理解,哪位大牛解释下grep的原理?

论坛徽章:
0
2 [报告]
发表于 2010-06-21 19:32 |只看该作者
Select only those  lines  containing  matches that  form  whole  words

论坛徽章:
0
3 [报告]
发表于 2010-06-21 19:34 |只看该作者
你想要的可能是grep -o的结果

论坛徽章:
0
4 [报告]
发表于 2010-06-21 19:35 |只看该作者
那为什么没有匹配到
10.10.10.10 node-1_priv  

论坛徽章:
0
5 [报告]
发表于 2010-06-21 19:36 |只看该作者
我不是想要哪种结果,我是想知道为什么会这样

论坛徽章:
0
6 [报告]
发表于 2010-06-21 20:25 |只看该作者
man grep
-w里好像说了这个
              Select only those  lines  containing  matches  that  form  whole
              words.   The  test is that the matching substring must either be
              at the  beginning  of  the  line,  or  preceded  by  a  non-word
              constituent  character. Similarly, it must be either at the end
              of the line or followed by  a  non-word  constituent  character.
              Word-constituent   characters   are  letters,  digits,  and  the
              underscore.

论坛徽章:
0
7 [报告]
发表于 2010-06-21 20:34 |只看该作者
也就是说-w会打印出那些包含node-1的词的行,node-1后面必须是行结束或者是非字母,数字,或者下划线字符,所以结果是没问题的。

论坛徽章:
0
8 [报告]
发表于 2010-06-21 21:03 |只看该作者
回复 7# bbgg1983


   真有耐心,赞一个!

论坛徽章:
0
9 [报告]
发表于 2010-06-22 11:32 |只看该作者
{:3_198:}{:3_198:}{:3_198:}{:3_198:}

论坛徽章:
0
10 [报告]
发表于 2010-06-22 15:01 |只看该作者
回复 6# bbgg1983


    赞一个
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP