How to match a string not followed by a word using sed

后端 未结 4 492
-上瘾入骨i
-上瘾入骨i 2021-01-24 10:11

I need to delete all strings consisting of a hyphen followed by a whitespace, but only when the whitespace is not followed by the word \"og\". Example file:

Kult         


        
4条回答
  •  悲哀的现实
    2021-01-24 10:43

    This might work for you (GNU sed):

    sed -r 's/(- (og|eller))|- /\1/g' file
    

    This relies on alternation to re-replace specific cases and the empty backreference to replace the general case.

提交回复
热议问题