To update config.ini
, the stream-editor sed
can be used to edit config.ini
in place and replace both <value_dev>
and <value_test>
with any values you like. To do so you will use the normal substitute form s/find/replace/
and you will include a pattern match before the substituted to only perform the substitution if the start of the line matches the pattern. For example for <value_dev>
you can use an expression such as:
sed -i -e '/^parameter_dev/s/<value_dev>/real_dev_value/' conf.ini
The with only match a line beginning with "parameter_dev"
and then will find <value_dev>
in the line and replace it with real_dev_value
. If you are calling it from within a script and want to replace with the value contained in the variable $real_dev_value
, then you must use double-quotes instead of single-quotes so that variable-expansion takes place.
You can handle both replacements in a single call by simply adding another expression, e.g.
sed -i -e '/^parameter_dev/s/<value_dev>/real_dev_value/' -e \
'/^parameter_test/s/<value_test>/real_test_value/' conf.ini
The option -i
tells sed
to edit the file in-place. Each -e
option introduces a new expression to be applied to the file.
If using a variable for the replaced value, the double-quoted form allowing variable expansion would be:
sed -i -e "/^parameter_dev/s/<value_dev>/$real_dev_value/" -e \
"/^parameter_test/s/<value_test>/$real_test_value/" conf.ini
Either form, using fixed strings or variables for replacement can be used on the command line or called from within a script.
Let me know if you have any questions.