正则表达式

1.行首与行尾字符^$

行首:

oyzhx@ubuntu:~$ grep -n '^the' regular_express.txt 
12:the symbol '*' is represented as start.   
行尾

oyzhx@ubuntu:~$ grep -n '\.$' regular_express.txt 
1:"Open Source" is a good mechanism to develop programs.

2.任意个字符.与重复字符*

*:重复前一个字符的0-无穷个的意思.//a*

oyzhx@ubuntu:~$ grep -n 'ooo*' regular_express.txt 
1:"Open Source" is a good mechanism to develop programs.
2:apple is my favorite food.
3:Football game is not use feet only.
9:Oh! The soup taste good.
18:google is the best tools for search keyword.
19:goooooogle yes!
.:代表一定有一个任意字符的意思.

oyzhx@ubuntu:~$ grep -n 'g..d' regular_express.txt 
1:"Open Source" is a good mechanism to develop programs.
9:Oh! The soup taste good.
16:The world <Happy> is the same with "glad".
".*"代表零个或多个任意字符

oyzhx@ubuntu:~$ grep -n 'g.*g' regular_express.txt 
1:"Open Source" is a good mechanism to develop programs.
14:The gd software is a library for drafting programs.
18:google is the best tools for search keyword.
19:goooooogle yes!
20:go! go! Let's go.

3.限定连续RE字符范围{}

{2}表示2个,{2,}2个以上,{2,5}2个到5个

oyzhx@ubuntu:~$ grep -n 'go\{2,5\}g' regular_express.txt 
18:google is the best tools for search keyword.
4.sed工具

sed [-nefr]

-n:显示n特殊处理的那行

-e:命令行模式上进行sed的动作编辑

-f:将sed的动作写在一个文件内

-r:扩展型正则表达式的语法(默认是基础正则表达式语法)

-i:直接修改读取的文件内容,而不是由屏幕输出

[n1,[n2]] function

function 的参数

a,新增;c替换 d删除,i插入;p打印,s替换

5.扩展正则表达式

+:重复一个或一个以上的前一个RE字符. egrep -n 'go+d' aa.txt;

?:零个或一个的前一个RE字符  egrep -n 'go?d' aa.txt;

|:用或(or)的方式找出数个字符串 egrep -n 'gdlggod' aa.txt;

():找出“组字符串” egrep -n 'g(laloo)d' aa.txt;

()+:多个重复组的判别  echo 'AxyzxyzxuzusC'|egrep 'A(xyz) +C';

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值