免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: sxlwzl
打印 上一主题 下一主题

[文本处理] grep查找某一类文件的匹配 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-07-04 17:44 |显示全部楼层 |倒序浏览
本帖最后由 sxlwzl 于 2014-07-04 17:46 编辑

1,需求:
一个目录下有.cc .c .h .pl .tcl文件,分布在不同的目录下
现在需要查找在所有的.tcl文件中,查找“关键字”

2,实现:
find -name "*.tcl" | sed -n "s/.*/grep -wrin chinaunix &/e"
但是没有找到任何文件。

3,debug
$cat ./tcl/test.tcl
chinaunix
i can not use
find -name "*.tcl" | sed -n "s/.*/grep -wrin chinaunix &/e"
find chinaunix
$ find -name "*.tcl" | sed -n "s/.*/grep -wrin chinaunix &/p"
grep -wrin chinaunix ./tcl/test.tcl

4,求问,为什么不能用“grep -wrin chinaunix ./tcl/test.tcl” 来使用grep呢,大家有没有什么好的方法来实现这个需求。


论坛徽章:
0
2 [报告]
发表于 2014-07-04 17:53 |显示全部楼层
回复 1# sxlwzl
google了一下,找到解决方案了。
grep -wrin chinaunix `find -name "*.tcl"`

疑问:为什么使用管道就是行呢?求各位大神指点迷津。
   

论坛徽章:
0
3 [报告]
发表于 2014-07-07 16:26 |显示全部楼层
回复 3# dn833


加了-wrin 四个选项

论坛徽章:
0
4 [报告]
发表于 2014-07-07 16:27 |显示全部楼层
回复 7# daxuewuhen2014


    应该对的,我经常用的。

论坛徽章:
0
5 [报告]
发表于 2014-07-07 17:55 |显示全部楼层
rulebook 发表于 2014-07-07 16:46

can you tell why?

论坛徽章:
0
6 [报告]
发表于 2014-07-07 22:08 |显示全部楼层
回复 10# rulebook


  这样就不知道是那个文件了。大家有没有什么好的办法,技能grep到,而且还能显示grep到的文件。

论坛徽章:
0
7 [报告]
发表于 2014-07-08 23:42 |显示全部楼层
回复 13# rulebook


    -H果真管用,谢谢
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP