sed 与正则表达式组合应用(一)

sed 与正则表达式组合格式

sed ‘/正则表达式/sed命令‘

1、区分大小写

$ echo "This is a test" |sed -n '/this/p'

$ echo "this is a test" |sed -n '/this/p'
this is a test


2、模式匹配的文本要大于或等于 表达式集合

$ echo "The books are expensive" | sed -n '/book/p'
The books are expensive
$ echo "The book are expensive" | sed -n '/books/p'
$ echo "The books are expensive" | sed -n '/book/p'
The books are expensive

$ echo "This is line number 1" | sed -n '/number 1/p'
This is line number 1


3、识别空格

$ cat >data1
This is a normal line of text.
This is a line with too many spaces.
$ sed -n '/ /p' data1
This is a line with too many spaces.


4、支持定位符^ $

$ echo "The book store" | sed -n '/^book/p'
$ echo "book store" | sed -n '/^book/p'
book store
$ echo "This ^ is a test" | sed -n '/s ^/p'
This ^ is a test

$ cat data4
this is a test of using both anchors
I said this is a test

this is a test

I'm sure this is a test
$ sed -n '/^$/d' data4
$ sed '/^$/d' data4
this is a test of using both anchors
I said this is a test
this is a test

I'm sure this is a test


5、支持. 字符代替任何字符

$ cat >data6

This is a test of a line

The cat is sleeping.
That is a very nice cat.
This test is at line four.
at ten o'clock we'll go home.

$ sed -n '/.at/p' data6
The cat is sleeping.
That is a very nice cat.
This test is at line four.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值