William126

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

 

posted on 2019-02-18 16:23  William126  阅读(131)  评论(0编辑  收藏  举报

导航