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/ 
相关推荐
光电的一只菜鸡7 小时前
ubuntu之坑(二十)——VMware虚拟机系统无法正常进入如何处理
linux·运维·ubuntu
你住过的屋檐8 小时前
【Nginx】linux上安装nginx
linux·运维·nginx
宵时待雨9 小时前
linux笔记归纳17:传输层协议UDP
linux·笔记·udp
SCandL15210 小时前
k8s service
linux·容器·kubernetes
会飞的土拨鼠呀11 小时前
Linux的存储使用率应该如何计算
linux·运维·服务器
weixin_5112552113 小时前
NGINX常用配置
linux·服务器·nginx
昌原的儿子LEO13 小时前
进程和线程(2)
linux·服务器·网络
会飞的土拨鼠呀14 小时前
Linux 真实内存使用率的核心计算标准
linux·运维·服务器
陈年老古董15 小时前
CentOS编译安装Python3.11完整教程
linux·笔记·学习·centos·python3.11
深念Y15 小时前
为什么选 Go:直观、可维护、AI 友好
linux·开发语言·人工智能·golang·agent·harness