总结:
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.youkuaiyun.com/tsxw24/article/details/7828357