This line works:
sed -r -e 's/^([^#a-z]+)localhost/\1hostname.domain hostname localhost/' /etc/hosts
But adding the itty option "i":
sed -ir -e 's/^([^#a-z]+)localhost/\1hostname.domain hostname localhost/' /etc/hosts
Results in:
sed: -e expression #1, char 60: invalid reference \1 on `s' command's RHS
Can someone tell me what’s going on??
You’ve turned off the
-r(extended syntax) option, because what you append to-iisn’t more options, but an optional backup suffix. From the manpage:So just separate them: