免费注册 查看新帖 |

Chinaunix

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

[文本处理] grep 结果异常? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-09-10 17:18 |只看该作者 |倒序浏览
[work@w-m2 ~/software/hbase/conf]$ grep -n  'ratio' *.xml
hbase-default.xml:2:<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
hbase-default.xml:24:<configuration>
hbase-default.xml:125:    operations such as fetching of the root region from root region
hbase-default.xml:361:    all updates across the duration of the compaction.
hbase-default.xml:546:    of operation. For a fully-distributed setup, this should be set to a full
hbase-default.xml:572:  ZooKeeper's configuration. Hence, if you want to add an option from zoo.cfg,
hbase-default.xml:573:  e.g.  "initLimit=10" you would append the following to your configuration:
hbase-default.xml:658:</configuration>
hbase-site.xml:2:<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
hbase-site.xml:24:<configuration>
hbase-site.xml:77:</configuration>
[work@w-m2 ~/software/hbase/conf]$

为什么会出现这个匹配结果?

论坛徽章:
0
2 [报告]
发表于 2012-09-10 17:27 |只看该作者
因为它们都含有ratio字符

论坛徽章:
145
技术图书徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11狮子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龙
日期:2014-01-08 15:26:12技术图书徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
3 [报告]
发表于 2012-09-10 17:30 |只看该作者
回复 1# guocanwen

Did you like to match word(-w) only

$ echo 'configration
test ratio
test configration
test 123' | grep -n ratio
1:configration
2:test ratio
3:test configration

$ echo 'configration
test ratio
test configration
test 123' | grep -n -w ratio
2:test ratio

   

论坛徽章:
0
4 [报告]
发表于 2012-09-10 17:36 |只看该作者
本帖最后由 xiaobai2621 于 2012-09-10 17:36 编辑

结果是正常的。你这个是搜索当前目录,所有的.xml文件中包含关键字ratio的行。

论坛徽章:
0
5 [报告]
发表于 2012-09-10 17:41 |只看该作者
回复 2# kk5234


    看错了,没注意configuration包含这这个子串

论坛徽章:
0
6 [报告]
发表于 2012-09-10 17:44 |只看该作者
建议你在使用grep的时候,加个参数
alias grep='grep --color=auto'
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP