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]*$/
  • /\<fourth\>/
  • /\<f.*th\> /
  • /5{2}2{3}\./
  • /^[\t]*$/
  • /^#/
  • /^[\t]*#/
  • :1,$ s/\([Oo]ccur\)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/ 
相关推荐
Eternity∞10 分钟前
基于Linux系统vim编译器情况下的C语言学习
linux·c语言·开发语言·学习·vim
芝麻馅汤圆儿18 分钟前
cpu 大小核
linux·运维·centos
牛奶咖啡1344 分钟前
shell脚本编程(三)
linux·shell脚本编程·环境变量的设置与取消·位置参数变量与内部参数变量·返回与退出状态·让变量获取键盘输入内容·使用decalre声明变量
2401_890443021 小时前
Linux进程间通信
linux·服务器
Xの哲學1 小时前
Linux 实时调度机制深度解析
linux·服务器·网络·算法·边缘计算
张太行_1 小时前
Linux信号处理函数中断流程分析
linux
晚风吹人醒.1 小时前
iptables防火墙规则(一):iptables语法结构,netfilter功能详解及案例演示
linux·服务器·网络·iptables·防火墙··netfilter
学好statistics和DS1 小时前
两个子进程都sleep, `waitpid` 系统调用
linux·服务器·数据库
シ風箏2 小时前
AutoGen【部署 02】Linux环境安装部署AutoGenStudio并调用本地 qwen2.5:0.5b 大模型举例
linux·autogen·本地大模型·autogenstudio
xingzhemengyou12 小时前
LINUX 通过/proc/interrupts了解系统硬件中断的使用情况
linux·arm开发