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/ 
相关推荐
牢姐与蒯38 分钟前
Linux基本指令及知识点(二)
linux·运维·服务器
小玮看世界40 分钟前
[Python]从“脏”数据到优雅实现:一个IoT滑动窗口最大值问题的测试驱动优化实录
linux·前端·python
BLi4ee2 小时前
WSL 文件资源管理器左侧 Linux / Ubuntu 入口恢复
linux·ubuntu
吴声子夜歌3 小时前
正则表达式——简单的模式匹配
正则表达式
BLUcoding3 小时前
Ubuntu 开机自启 Kiosk 模式浏览器全屏展示网页配置指南
linux·运维·ubuntu
Kina_C5 小时前
Keepalived 配置管理进阶:使用子配置文件实现模块化与高可读性
linux·网络·keepalived
wsad05325 小时前
CentOS Stream 10 配置静态 IP 完整指南
linux·tcp/ip·centos
Ai拆代码的曹操5 小时前
K8s 实战:CrashLoopBackOff 状态下 kubectl logs 拿不到日志的三层排查方案
linux·docker·kubernetes
tedcloud1235 小时前
Kimi-K3 部署指南:大模型应用开发环境搭建实践
linux·运维·服务器·开源·音视频
深念Y6 小时前
ZTE_UZ901_NVRAM经验总结
linux·服务器·网络·嵌入式硬件·嵌入式·随身wifi