linux中grep查询文件及字符串

发布时间:2021-07-16 17:07:32 阅读:1678次

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'

linux grep - 踏雪寻梅 - WEB程序员之家

linux grep - 踏雪寻梅 - WEB程序员之家 linux grep - 踏雪寻梅 - WEB程序员之家

三、从文件夹里面查询出包含字符串'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  {} \;

如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术

支付宝 微信

有疑问联系站长,请联系QQ:QQ咨询

转载请注明:linux中grep查询文件及字符串 出自老鄢博客 | 欢迎分享