grep快速查找某一类文件的技巧

总结:

1,grep -Hwrin chinaunix `find -name "*.tcl"` 查找速度非常快。4s

2,find -name "*.tcl" | sed -n "s/.*/grep -wrin chinaunix &/ep" 速度略慢,cmd比较复杂。20s

快5倍。


本帖最后由 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呢,大家有没有什么好的方法来实现这个需求。
$ find -name "*.tcl" | sed -n "s/.*/grep -wrin chinaunix &/ep"
同时使用ep就可以实现。但是对比起来grep -hwrin chinaunix `find . -name "*.tcl"`要慢很多。

google了一下,找到解决方案了。
grep -wrin chinaunix `find -name "*.tcl"`

添加-H属性,能看到所在文件:
grep -Hwrin chinaunix `find -name "*.tcl"`


原文: http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=4144656&pid=24229749&page=1&extra=page%3D1#pid24229749


参考:http://blog.csdn.net/tsxw24/article/details/7828357


  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值