50个常用的Linux命令(二)sed

[root@localhost cee]# echo this thisthisthis |sed 's/this/THIS/g'
THIS THISTHISTHIS
[root@localhost cee]# echo this thisthisthis |sed 's/this/THIS/2g'
this THISTHISTHIS
[root@localhost cee]# echo this thisthisthis |sed 's/this/THIS/3g'
this thisTHISTHIS
[root@localhost cee]# echo this thisthisthis |sed 's/this/THIS/4g'
this thisthisTHIS


[root@localhost cee]# cat temp
i love linux

i love python
william
[root@localhost cee]# sed '/^$/d' temp
i love linux
i love python
william
[root@localhost cee]# cat temp
i love linux

i love python
william

[root@localhost cee]# echo this is an example |sed 's/w+/[&]/g'
[this] [is] [an] [example]
[root@localhost cee]# echo this is an example |sed 's/w+/"&"/g'
"this" "is" "an" "example"
[root@localhost cee]# echo this is digit 7 in a number | sed 's/digit ([0-9])/1/g'
this is 7 in a number

[root@localhost cee]# echo seven EIGHT |sed 's/([a-z]+) ([A-Z]+)/2 1/g'
EIGHT seven

sed 'exp'|sed 'exp2' == sed 'exp;exp2'

[root@localhost cee]# text=hello
[root@localhost cee]# echo hello world | sed "s/$text/HELLO/g"
HELLO world

原文地址:https://www.cnblogs.com/william126/p/10396265.html