Global search regular expression(RE) ,简称grep;是一种强大的文本搜索工具,可以使用正则表达式搜索文本,并把匹配打印出来。

  1. -v #排除,取
  2. -n #显示行号
  3. -E #支持扩展正则表达式(与egrep作用相同)
  4. -i #==ignore-case忽略大小写
  5. -w #==word以单词格式查找
  6. -c #统计匹配上的行数(统计包含xxx的有多少行)
  7. -A #==after 匹配行的后几行
  8. -B #==before 匹配行的前几行
  9. -C #匹配行的前后几行
  10. -o #显示匹配过程
  11. -r #在目录下递归的在所有文件中查找需要的内容
    -s   #不显示不存在或无匹配文本的错误信息
    -l   #查询文件时只输出包含匹配文本的错误信息
    -h   #查询文件时不显示文件名

 

  1. grep -c "test" dks.txt
  1. grep -o "test" dks.txt |wc -l

 

  1. grep -n "test" dks.txt

 

  1. grep -i "tEst" dks.txt

 

  1. grep "test[53]" dks.txt

 

  1. grep "^[^test]" dks.txt

 

  1. grep "^[mM].*" dks.txt

 

  1. grep "K..D" dks.txt

 

  1. grep "[A-Z]9D" dks.txt
  1. grep "T\{2,\}" dks.txt

 

  1. grep "T\{2,6\}" dks.txt

 

  1. grep -n "^$" dks.tx
  1. grep -vE "^$|#" dks.txt

 

  1. grep -ra -E "db|config|sql" /data

 

  1. ifconfig eth0 |grep "inet "|grep -E "\<([0-9]{1,3}\.?){4}" -o|head -1

 

 

版权声明:本文为shitou-st原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/shitou-st/p/11798973.html