I have one file which contains key value pair
properties.env
development_port=8080
development_type=tcp
staging_port=8081
development_type=http
I need to read value from properties.env and replace it in another file based on some environment variable value lets say ENVIRONMENT=staging/development
config.yml
server:
adminConnectors:
-
port: 18001
type: http
The final output of config.yml should be if ENVIRONMENT=staging
server:
adminConnectors:
-
port: 8081
type: http
How can i achieve this using sed command?
Since the properties file looks like it has the right syntax you could just source it, and then replace the entire port line:
source properties.env
sed --in-place "s/port.*/port: $staging_port/" config.yml
This, of course, assumes the "port" line appears only once in your config.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.