I have a file and content is below.
subscription-manager register --org="Default_Organization" --activationkey="Dev Activation Key" &> /var/log/subs2.log
I want to append a few words
(--serverurl=https://siedgeprodsatellitelb.siedgemanagement.com:8443/rhsm
--baseurl=https://siedgeprodsatellitelb.siedgemanagement.com/pulp/repos) after --activationkey="Dev Activation Key"
So that it can look like below
sudo subscription-manager register --org="LDEdgeDevices" --activationkey="Dev Activation Key" --serverurl=https://siedgeprodsatellitelb.siedgemanagement.com:8443/rhsm --baseurl=https://siedgeprodsatellitelb.siedgemanagement.com/pulp/repos &> /var/log/subs2.log
I am using this sed command but it is throwing an error:
sed -i '/"Dev Activation Key"/ s/$/--serverurl=https://siedgeprodsatellitelb.siedgemanagement.com:8443/rhsm --baseurl=https://siedgeprodsatellitelb.siedgemanagement.com/pulp/repos /' test
Any suggestions?
CodePudding user response:
sed -i '/"Dev Activation Key"/ s/$/--serverurl=https://siedgeprodsatellitelb.siedgemanagement.com:8443/rhsm --baseurl=https://siedgeprodsatellitelb.siedgemanagement.com/pulp/repos /' test
Problem with that command: you have both /
which should be treated by sed
as command delimiters and /
which should be treated as literal /
(part of string), either escape /
which should be treated as literal /
or use another command delimiter (use character which does not appear inside string), consider following simple example, let file.txt
content be
https://www.example.com
https://www.example.com/123/abc
https://www.example.com/abc/123
and lets' say you want to replace /123/
using /456/
then you can do
sed 's/\/123\//\/456\//' file.txt
or
sed 's|/123/|/456/|' file.txt
to get output
https://www.example.com
https://www.example.com/456/abc
https://www.example.com/abc/123
(tested in GNU sed 4.2.2)
CodePudding user response:
sudo sed -i 's%subscription-manager register --org="Default_Organization" --activationkey="Dev Activation Key"%subscription-manager register --org="Default_Organization" --activationkey="Dev Activation Key" --serverurl=https://siedgeprodsatellitelb.siedgemanagement.com:8443/rhsm --baseurl=https://siedgeprodsatellitelb.siedgemanagement.com/pulp/repos%g' test
Just changed / to %