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

  • grep love 1.txt
  • /^love/
  • /love$/
  • /l.ve/
  • /lo*ve/
  • /Llove/
  • /lovea-z/
  • /love\^a-zA-Z0-9
  • /.*/
  • /^$/
  • /^A-Z..$"/
  • /^A-Za-z*30-5/
  • /a-z*\."/
  • /^*A-Za-za-z$"/
  • /^*A-Za-z*\^,A-Za-z*$/
  • /\<fourth\>/
  • /\<f.*th\> /
  • /5{2}2{3}\./
  • /^\\t*$/
  • /^#/
  • /^\\t*#/
  • :1,$ s/\(Ooccur\)ence/\1rence/
  • :1,$ s /\(square\) and \(fair\)/\2 and \1/
cs 复制代码
[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 "\<fourth\>" 1.txt 
[root@localhost ~]# grep \<fourth\> 1.txt 
[root@localhost ~]# grep \<f.*th\> 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/ 
相关推荐
zh路西法16 小时前
【navigation2全局路径更新频率修正】行为树框架的巧妙利用
linux
苏宸啊17 小时前
IPC管道
linux·c++
bush417 小时前
嵌入式linux学习记录十,定时器
linux·嵌入式
峥无17 小时前
Linux进程信号:从基础概念到内核底层原理
linux·运维·服务器·信号处理
广州灵眸科技有限公司17 小时前
瑞芯微RV1126B开发板(EASY-EAI-PI2) 开发(编译)方式说明
linux·服务器·单片机·嵌入式硬件·电脑
北山有鸟18 小时前
用开发板的.config替换ubuntu中内核源码目录的.config
linux·运维·ubuntu
jcbut18 小时前
离线安装dify 1.7
linux·运维·dify
云计算磊哥@18 小时前
运维开发宝典024-Linux云计算运维入门阶段总结
linux·运维·运维开发
江华森19 小时前
《Linux内核技术实战:从Page Cache到CPU调度的深度解构》博客大纲(26讲精编版)
linux
知无不研19 小时前
对套接字的深入理解
linux·服务器·网络·c++·socket·网络套接字