How to globally replace strings in lines NOT starting with a certain pattern

前端 未结 3 1885
庸人自扰
庸人自扰 2020-12-23 17:13

I want to globally replace the string foo with the string bar, using sed. This should only be done for lines which do NOT start with the string ##Input.

I can\'t get

3条回答
  •  渐次进展
    2020-12-23 17:55

    You just need to negate the match using !:

    sed -i '/^##Input/! s/foo/bar/g' myfile
    

提交回复
热议问题