本文介绍了sed 递归替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
echo ddayaynightday |sed 's/day//g'
它结束了daynight
有没有办法让它替代直到不再匹配?
Is there anyway to make it substitute until no more match ?
推荐答案
我的首选形式,对于这种情况:
My preferred form, for this case:
echo ddayaynightday | sed -e ':loop' -e 's/day//g' -e 't loop'
这和其他人的一样,除了它使用多个 -e 命令来组成三行并使用 t
构造——这意味着如果你成功替换了分支"——迭代.
This is the same as everyone else's, except that it uses multiple -e commands to make the three lines and uses the t
construct—which means "branch if you did a successful substitution"—to iterate.
这篇关于sed 递归替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!