how to replace two things at once with sed?

后端 未结 2 1219
野趣味
野趣味 2021-01-31 17:46

Given is string: dog apple orange banana

I need to make it: monkey apple cow banana

That is without calling sed twice.

相关标签:
2条回答
  • 2021-01-31 18:09

    The following sed example should solve your problem. sed allows multiple -e switches, which allows you to replace more than one thing at a time.

    sed -e 's/dog/monkey/g' -e 's/orange/cow/g'
    
    0 讨论(0)
  • 2021-01-31 18:21

    Use ; to queue commands:

    sed -e 's/dog/monkey/g;s/orange/cow/g'
    
    0 讨论(0)
提交回复
热议问题