So I am using sed to find and replace certain strings:
Case 1. A value in the file is always constant. And I want to replace the parameter from false to true. So I use this command:
sed -i -e 's/entry key="ignore_vc_cert" value="false"/entry key="ignore_vc_cert" value="true"/g' /usr/local/avamar/var/mc/server_data/prefs/mcserver.xml
This will find ignore_vc_cert
and change its value from false
to true
. Works good.
Next,I have another file which has the following parameter:
<numberOfDisk>4</numberOfDisk>
Now, this value here can change depending on deployment. I want to replace the number here, 4
, or whatever with the output of df -h | grep data0* | wc -l
So if output of df -h | grep data0* | wc -l
is 3
it should replace the value for numberOfDisk
Parameter from 4
to 3
I wrote this command:
sed -e s/"$(cat /usr/local/vdr/etc/vdr-configuration.xml | grep -i numberOfDisk)"/<numberOfDisk>"$(df -h | grep data0* | wc -l)"</numberOfDisk>/g > /usr/local/vdr/etc/vdr-configuration.xml
But form some reason, I get numberOfDisk: No such file or directory
If I do:
sed -e 's/"$(cat /usr/local/vdr/etc/vdr-configuration.xml | grep -i numberofdisk)"/<numberOfDisk>"$(df -h | grep data0* | wc -l)"</numberOfDisk>/g' /usr/local/vdr/etc/vdr-configuration.xml
Then I get: sed: -e expression #1, char 15: unknown option to
s'`
Any inputs on how I could fix this?