Sed substitute recursively

前端 未结 6 843
我在风中等你
我在风中等你 2020-12-28 18:35

echo ddayaynightday | sed \'s/day//g\'

It ends up daynight

Is there anyway to make it substitute until no more match ?

6条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-28 19:30

    My preferred form, for this case:

    echo ddayaynightday | sed -e ':loop' -e 's/day//g' -e 't loop'
    

    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.

提交回复
热议问题