Search code examples
linuxsedbackreferencein-place

in-place backreferencing with sed


Can anyone help explain why

sed -re 's/(e)\1{2,}/ee/g' filename

Outputs (as desired)

Jeep

But

sed -ire 's/(e)\1{2,}/ee/g' filename

Gives me

sed: -e expression #1, char 16: Invalid back reference

I've tried fiddling around and putting escape brackets in different places but I'm not sure what else to do now.


Solution

  • Because -ire specifies re as the argument to -i, not as options to sed.

    Specifying -i as a separate individual option works fine.

    sed -i -re 's/(e)\1{2,}/ee/g' file