Bash Shell ---- delimiter@sed

本文介绍了sed命令中的替换功能,并展示了如何灵活使用不同的分隔符来提高命令的可读性和适用性。通过实例演示了除斜杠外还可以选择其他字符作为分隔符的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

With the substitution command, we can handle 90% of the most frequent uses of sed. But there are so many features that we cannot miss it! Delimiter is one of them.

We can see the examples that use slash as the delimiter frequently when we are searching for the examples. But I think few people knows that we can use character as the delimiter. Let's see the examples now.

examples:

1.sed 's/\/etc\//\/myEtc\//g' paths

This example uses the slash as delimiter. Most of us love the slash because we use the slash in vi/vim, ed, more, less and so on. We may find the slash is everywhere. But it may not be a good idea to use it here. We call this command  'Picket Fence'. It is ugly to most of us.

b_large_WnyZ_124c00003f3a1262.jpg

2.sed 's_/etc/_/myEtc/_g' paths

In fact, we can use any character that we like. 

Someone uses '/' while others uses '_'. What's more, the sed won't be angry if you use ':' or ';'.

转载于:https://www.cnblogs.com/Neoh/archive/2012/09/28/2706993.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值