Shell三剑客:正则表达式(元字符)——示例

  • grep love 1.txt
  • /^love/
  • /love$/
  • /l.ve/
  • /lo*ve/
  • /[Ll]ove/
  • /love[a-z]/
  • /love[^a-zA-Z0-9]
  • /.*/
  • /^$/
  • /^[A-Z]..$"/
  • /^[A-Z][a-z]*3[0-5]/
  • /[a-z]*\."/
  • /^*[A-Z][a-z][a-z]$"/
  • /^*[A-Za-z]*[^,][A-Za-z]*$/
  • /\/
  • /\ /
  • /5{2}2{3}\./
  • /^[\t]*$/
  • /^#/
  • /^[\t]*#/
  • :1,$ s/\([Oo]ccur\)ence/\1rence/ 
  • :1,$ s /\(square\) and \(fair\)/\2 and \1/ 
[root@localhost ~]# grep "^$" 1.txt 
[root@localhost ~]# grep ".*" 1.txt 
#qian
#yoa
#huang
kai
kong
cai
[root@localhost ~]# grep "^$" 1.txt 
[root@localhost ~]# grep "[A-Z]..$" 1.txt 
[root@localhost ~]# grep "[^A-Z]..$" 1.txt 
#qian
#yoa
#huang
kai
kong
cai
duo
[root@localhost ~]# grep "^[A-Z]..$" 1.txt 
[root@localhost ~]# grep "^[A-Z][a-z]*3[0-5]" 1.txt 
[root@localhost ~]# grep "[a-z]*\." 1.txt 
l.ve
[root@localhost ~]# grep "^*[A-Z][a-z][a-z]$" 1.txt 
[root@localhost ~]# grep "^*[A-Za-z]*[^,][A-Za-z]*$" 1.txt 
[root@localhost ~]# grep "\" 1.txt 
[root@localhost ~]# grep \ 1.txt 
[root@localhost ~]# grep \ 1.txt 
[root@localhost ~]# grep "5{2}2{3}\." 1.txt 
[root@localhost ~]# grep "^[\t]*$" 1.txt 
[root@localhost ~]# grep "^#" 1.txt 
#qian
#yoa
#huang
[root@localhost ~]# grep "^[\t]*#" 1.txt 
#qian
#yoa
#huang
:1,$ s/\([Oo]ccur\)ence/\1rence/ 
:1,$ s /\(square\) and \(fair\)/\2 and \1/ 

Shell三剑客:正则表达式(元字符)——示例_第1张图片 

Shell三剑客:正则表达式(元字符)——示例_第2张图片 

Shell三剑客:正则表达式(元字符)——示例_第3张图片 

Shell三剑客:正则表达式(元字符)——示例_第4张图片 

你可能感兴趣的:(Shell,正则表达式,linux,bash,shell)