正则表达式 egrep

一.扩展正则表达式的概述

使用扩展正则表达式,需要使用egrep命令,egrep命令是一个搜索文件获得模式,使用该命令可以搜索文件中的任意字符串和符号,可以搜索一个或者多个文件的字符串,一个提示符可以是单个字符、一个字符串、一个字或一个句子
二.扩展正则表达式的元字符

+,重复零个或者多个的前一个字符
[root@localhost ~]# egrep -n 'wo+d' a.txt5:wood6:wooood12:wod13:wood14:wooooood[root@localhost ~]# 

?,查询是否存在有前一个字符
[root@localhost ~]# egrep -n 'bes?t' a.txt 17:best18:bet[root@localhost ~]# 

| ,使用或者(or)的方式找出多个字符
[root@localhost ~]# egrep -n 'of|if|on' a.txt19:often20:ifconfig22:ontime[root@localhost ~]# 

(),查找“组”字符串
[root@localhost ~]# egrep -n 'be(s|a)t' a.txt17:best23:beat[root@localhost ~]# 

()+ ,辨别多个重复的组
[root@localhost ~]# egrep -n 'A(xyz)+C' a.txt24:AxyzC25:AxyzxyzC

 
 

发布了44 篇原创文章 · 获赞 10 · 访问量 1015

猜你喜欢

转载自blog.csdn.net/weixin_45725244/article/details/103519456