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/ 
相关推荐
van叶~5 分钟前
Linux网络-------1.socket编程基础---(TCP-socket)
linux·网络·tcp/ip
风吹落叶花飘荡18 分钟前
Ubuntu系统 系统盘和数据盘扩容具体操作
linux·运维·ubuntu
zoulingzhi_yjs1 小时前
haproxy配置详解
linux·云原生
bingbingyihao1 小时前
Node.js 模拟 Linux 环境
linux·node.js
大神的风范1 小时前
从0开始学linux韦东山教程Linux驱动入门实验班(5)
linux
小码过河.1 小时前
CentOS 搭建 Docker 私有镜像仓库
linux·docker·centos
贾斯汀玛尔斯3 小时前
ubuntu/centos系统ping 不通域名的解决方案
linux·ubuntu·centos
fhf4 小时前
2025年了你会卸载Macbook上的应用吗?
macos·shell
呆瑜nuage4 小时前
Linux的工具
linux
唐青枫4 小时前
Linux vimgrep 详解
linux·vim