主旨:   grep    正则   

shell学习-grep

示例:  cp  /etc/passwd 1.txt 

shell学习-grep

alias:别名使用:  此时使用grep  相当于grep  --color  

shell学习-grep

shell学习-grep

 

-A  -B  -C

shell学习-grep

shell学习-grep

n$   :指以n结尾

shell学习-grep

^a:以a为开头

shell学习-grep

 

     [^0-9]: 指非0-9          -v:指的是不带  0-9   grep  -v  [0-9] 1.txt

shell学习-grep

 

grep 特殊字符 :    1 . :点   2. ?问号  3.+ 加号   4.{}  括号   5. \  转义  

 

*  :表示0个或多个前面的字符 

如  grep 'ro*t' 1.txt   rt 和 rooooot 匹配  但是 roasdflasdt  :不匹配

shell学习-grep

 

点:.   :任意一个字符 (不管是空格  特殊符号还是别的)

shell学习-grep

 

?:问号    在shell中表示任意一个字符和点类似,但是在grep 正则中意思为:0个或1个前面的字符 

如:  ‘ro?t’  只有rt  rot   rotaaldsl  才匹配    rooot 不匹配

使用时需要加 -E  否则不生效

或者  egrep   --color 'ro?t' 1.txt   和 grep  -E 'ro?t' 1.txt  效果一样

shell学习-grep

 

+:加号   :1个或多个前面的字符

shell学习-grep

总结:

shell学习-grep

 

.*   :点  *   : 任意字符   贪婪匹配  

shell学习-grep

 

shell学习-grep

shell学习-grep

其中   |  grep 也不支持, egrep 才支持  

shell学习-grep

shell学习-grep

shell学习-grep

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-05
  • 2022-12-23
  • 2022-03-01
  • 2021-12-27
  • 2022-01-04
猜你喜欢
  • 2021-06-07
  • 2021-08-22
  • 2021-10-11
  • 2022-12-23
  • 2021-11-21
相关资源
相似解决方案