我有以下文字:
client_encryption_options:
enabled: true
# If enabled and optional is set to true encrypted and unencrypted connections are handled.
optional: false
keystore: conf/.keystore
keystore_password: cassandra
我正在尝试使用 sed 命令更改 client_encryption_options 下密钥库中的值。
sed "/^client_encryption_options:/,+1s/keystore:.*/keystore: \/opt\/test/" $CASSANDRA_YAML_FILE > cassandra.yaml.tmp && mv cassandra.yaml.tmp $CASSANDRA_YAML_FILE
当我尝试上述命令时,它不会将 conf/.keystore 替换为/opt/test/
答案1
答案2
sed -e '
/^client_encryption_options:/,/keystore:/!b
//!b
s|\(keystore:\).*|\1 /opt/test|
' < $CASSANDRA_YAML_FILE > cassandra.yaml.tmp && \
mv cassandra.yaml.tmp "$CASSANDRA_YAML_FILE"
如果您的“sed”支持它,您甚至可以使用“-i”(就地编辑)选项来消除“mv”:
sed -i.BAK -e 'your edit commands here' $_YOUR_YAML_FILE # Note: NO redirections here