Replace whole line when match found with sed

前端 未结 4 1766
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-07 20:25

I need to replace the whole line with sed if it matches a pattern. For example if the line is \'one two six three four\' and if \'six\' is there, then the whole

4条回答
  •  一整个雨季
    2020-12-07 20:44

    Above answers worked fine for me, just mentioning an alternate way

    Match single pattern and replace with a new one:

    sed -i '/six/c fault' file
    

    Match multiple pattern and replace with a new one(concatenating commands):

    sed -i -e '/one/c fault' -e '/six/c fault' file
    

提交回复
热议问题