What's wrong with my lookahead regex in GNU sed?

前端 未结 3 488
感动是毒
感动是毒 2020-11-30 02:42

This is what I\'m doing (simplified example):

gsed -i -E \'s/^(?!foo)(.*)$/bar\\1/\' file.txt

I\'m trying to put bar in front

3条回答
  •  野性不改
    2020-11-30 03:25

    sed -i '/^foo/! s/^/bar/' file.txt
    
    • -i change the file in place
    • /^foo/! only perform the next action on lines not ! starting with foo ^foo
    • s/^/bar/ change the start of the line to bar  

提交回复
热议问题