http://blog.csdn.net/diy534/article/details/7025640
在linux下给grep命令添加颜色
grep -o仅显示匹配的个数
匹配以数字开头的
[root@10-10-67-217 data]# grep ^[0-9] business12.csv
4748959,1499466969,"HNReport.exe","Heinote","2.0.0.4","222.188.114.102","13286000650173CF35841690BB85F33F",1499466915,"yx_002",170708,"Windows 7 Professional","0.128\
匹配不对数字开头的
[root@10-10-67-217 data]# grep -v '^[0-9]' business12.csv
","00-50-56-90-6A-ED","1FABFBFF000306F2","13286000650173CF35841690BB85F33F","1afb65ebf0de485132675c6b6c9a3a06","updatechecker.run",1,1,1,1,0,4,1,0
pi@bananapi ~/shell $ grep 'for' -A 1 ./*
./checkip2.sh:for ip in 192.168.0.{1..255}
./checkip2.sh-do
--
./checkip.sh:for ip in 192.168.0.{1..255}
./checkip.sh-do
--
./check.sh:for (( i=1; i<255; i++ )) do ping -c1 -w1 $1.$i > /dev/null
./check.sh- if [ $? -eq 0 ]
查找带特殊符号的字符串
cat 1.sql | grep --color "\`sdb_article\`"
cat 1.sql | grep "INSERT INTO \`sdb_article\`"
grep的几种使用方法
一、grep " $str" $filename
二、echo|cat $str | grep 'str'
三、从文件夹里面查询出包含字符串'test'的文件
grep 'test' ./*
四、从文件夹中查询出符合的文件,再从这些文件中查找包含要找的字符串的文件
find -name "*.*" -exec grep --color -n "ceshi" {} \;
五、从文件夹中查询出符合的文件,再从这些文件中查找包含要找的字符串的文件,并显示文件名
find -name "*.php" |xargs grep --color -n "hello" -H {} \;
或
find -name "*.php" -exec grep --color -n "hello" -H {} \;