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/ 
相关推荐
utf8mb4安全女神12 分钟前
磁盘管理(交换分区)(MGR分区)(GPT分区)
linux·运维·服务器
不会就选b13 分钟前
linux之vim
linux·运维·vim
2301_7779983428 分钟前
进程控制:进程创建、进程终止、进程等待、进程程序替换
linux·服务器
xiaobobo333035 分钟前
Ubuntu 26.04下编译s5pv210芯片的linux内核源码,无法进入menuconfig界面
linux·运维·ubuntu
REDcker1 小时前
Linux文件IO底层原理详解
linux·运维·spring
为思念酝酿的痛1 小时前
线程同步与互斥
linux·运维·服务器·后端
一条代码鱼1 小时前
Linux 文件实时同步完全指南:Lsyncd vs Inotifywait+Rsync
linux·运维·服务器
艾莉丝努力练剑1 小时前
【Linux网络】Linux 网络编程:传输层协议TCP(三)
linux·运维·服务器·网络·tcp/ip·http
keyipatience1 小时前
21,22 (半)深入理解Linux重定向与缓冲区机制
linux·运维·服务器
fengyehongWorld1 小时前
Linux command 命令
linux