Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 639
André Foote Avatar asked Jan 21 '26 15:01

André Foote


1 Answers

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
like image 54
tripleee Avatar answered Jan 24 '26 08:01

tripleee



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!