If someone can please assist, I'm trying to do a sed append using regex and capture groups but its not working fully:
echo "#baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/" | sed -re '/#baseurl=http:\/\/mirror.centos.org(.*)/a baseurl=https:\/\/10.10.10.10\ \1'
#baseurl=http://mirror.centos.org/centos//contrib//
baseurl=https://10.10.10.10 1
At the moment it is just giving the literal value 1 rather than the capture group.
It should give:
#baseurl=http://mirror.centos.org/centos//contrib//
baseurl=https://10.10.10.10/centos//contrib//
I have tried backslash parentheses as well but its not working. Please assist....as it is hurting my head now...
You can only capture back-reference when using s
(substitute) command in sed
.
This should working:
s="#baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/"
sed -r 's~#baseurl=http://mirror\.centos\.org(.*)~&\nbaseurl=https://10.10.10.10\1~' <<< "$s"
#baseurl=http://mirror.centos.org/centos//contrib//
baseurl=https://10.10.10.10/centos//contrib//
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With