linux grep (linux查找关键字在php出现的次数)

http://www.th7.cn/system/lin/201508/127681.shtml

查找CleverCode在当前目录以及子目录,所有的php出现大于0的次数。


# find -type f -name '*.php' | xargs grep CleverCode ./*.php -rc | awk -F ':' '$2 > 0 {print $1,$2}' | grep -v '/.svn/' | sort -n -k 2 -r

1)find -type f -name '*.php'。查找当前目录以及子目录中所有的php文件。
2)xargs grep CleverCode ./*.php -rc。在每个文件中查找CleverCode关键字,并显示出现次数。
3)awk -F ':' '$2 > 0 {print $1,$2}'。用':'分割列,显示第2列>0的行。
4)grep -v '/.svn/' 。去掉.svn目录数据
5)sort -n -k 2 -r。按照第2列数组大小降序排序。

与上面结果相似

http://blog.sina.com.cn/s/blog_8317516b010103fx.html  xargs

find ./ -name spes.2016-03-2* | grep '6001973816' | cut -d ':' -f 1 |xargs ls -lrt

------------------------------------------------------------------------------------------------------------------------------------------------------------------

先查找行

grep -n '574844a2b2894c4383a2ccac8a3d72d53aabcf2184c44764' spes.2016-03-21_09.0.log --color

再查找大于这个行的上下文

awk 'NR>200934' spes.2016-03-21_09.0.log |grep -A 300 -B 50 '574844a2b2894c4383a2ccac8a3d72d53aabcf2184c44764'

------------------------------------------------------------------------------------------------------------------------------------------------------------------

原文地址:https://www.cnblogs.com/blogabc/p/5301181.html