I have an .yml file that configures environment properties of an application, such like this:
env1:
:prop1: "value1"
:prop2: "value2"
...
:propn: "valuen"
env2:
:prop1: "value1"
:prop2: "value2"
:prop3: "value3"
...
:propn: "valuen"
...
envn:
:prop1: "value1"
:prop2: "value2"
...
:propn: "valuen"
I would like to produce a bash script with the following interface:
$ change_env.sh <environment> <property> <new value> <file.yml>
Example:
$ change_env.sh env2 prop3 "this value was changed" file.yml
The output will be:
env1:
:prop1: "value1"
:prop2: "value2"
...
:propn: "valuen"
env2:
:prop1: "value1"
:prop2: "value2"
:prop3: "this value was changed"
...
:propn: "valuen"
...
envn:
:prop1: "value1"
:prop2: "value2"
...
:propn: "valuen"
I found this post, however I could not do it work for my case. Replace an XML element's value? Sed regular expression?
I also tried this: (it fails because alters all properties)
sed 's/\(:pro3:\).*/\1 "new value"/'
Thanks in advance! -- Lourenco.