我想自动替换Redmine
配置文件的行。配置文件如下所示:
# MySQL (default setup).
....
production:
adapter: mysql
database: redmine
host: localhost
username: root
password:
encoding: utf8
development:
adapter: mysql
database: redmine_development
host: localhost
username: root
password:
encoding: utf8
....
我只想在生产部分之后替换密码,数据库等......
如何使用sed
?
答案 0 :(得分:2)
基于您的示例文件:
sed -r '/^production:/,/^$/{s/(\s*database:).*/\1newDB/;
s/(\s*password:).*/\1newPWD/}' yourConfig
上面的cmd会将“生产”部分中的“数据库”和“密码”设置更改为newDB和newPWD。 p>
输出:
...
production:
adapter: mysql
database:newDB
host: localhost
username: root
password:newPWD
encoding: utf8
development:
adapter: mysql
database: redmine_development
host: localhost
username: root
password:
encoding: utf8
...