linux grep命令


10. grep -E 扩展正则表达式
11. grep -o 只显示匹配成功的部分,而不是整行。
[root@k8s-node1 home]# grep 'yang' /home/* grep: /home/tools: 是一个目录 /home/yangjianbo:yang zhonguogren sdfsdfdsf [root@k8s-node1 home]# grep -o 'yang' /home/* grep: /home/tools: 是一个目录 /home/yangjianbo:yang
12. grep -A
-A<显示列数> 除了显示符合范本样式的那一行之外,并显示该行之后的内容。
grep -A 5 "aaaa" error.log
13. grep -B
-B 在显示符合范本样式的那一行之外,并显示该行之前的内容。
grep -B 5 "aaaa" error.log
14. grep -r
#只在目录中所有的.php和.html文件中递归搜索字符"main()"
# grep"main()" . -r --include *.{php,html}
#在搜索结果中排除所有README文件
# grep"main()" . -r --exclude "README"
#在搜索结果中排除filelist文件列表里的文件
# grep"main()" . -r --exclude-from filelist
15. 批量修改某类文件的某个字符为另外一个
sed -i 's#a#b#g' `grep "a" . -rl --include "*.*"`
一往无前虎山行,拨开云雾见光明

浙公网安备 33010602011771号