yegor256 yegor256 - 3 years ago 96
Linux Question

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

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

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

I'm trying to put
in front of every line that doesn't start with
. This is the error:

gsed: -e expression #1, char 22: Invalid preceding regular expression

What's wrong?

Answer Source

As far as I know sed has not neither look-ahead nor look-behind. Switch to a more powerful language with similar syntax, like perl.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download