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

本文深入探讨了SED命令在文本处理中的高级应用,包括替换字符串、删除空行、使用正则表达式等技巧,通过实际案例展示了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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值