Pipe Unixコマンドを使用してファイルのパターンを永久に置き換える方法

Pipe Unixコマンドを使用してファイルのパターンを永久に置き換える方法

次の行があるので具体的に変えたいです。

client_encryption_options:
    enabled: true                    

到着

client_encryption_options:
    enabled: false
client_encryption_options:
    enabled: true
    # If enabled and optional is set to true, encrypted and unencrypted connections over native transport are handled.
    optional: false
    keystore: XXXXXX
    keystore_password: XXXXX

    # Set require_client_auth to true to require two-way host certificate validation
    require_client_auth: true
    #
    # Set truststore and truststore_password if require_client_auth is true

ベストアンサー1

入力はYAMLファイルなので、コマンドラインYAMLパーサーを使用できますyqhttps://kislyuk.github.io/yq/

yq -y '.client_encryption_options.enabled |= false' file.yml

これにより、enabled最上位オブジェクトのキー値がに更新されます。client_encryption_optionsfalse

変更を適用するには、そのオプションまたはオプションと組み合わせてyq使用​​してください。--in-place-i

これはyqJSONラッパーを囲むラッパーjqなので、ドキュメントからコメントが削除されます。


yqが提供するプログラムを使用する場合https://mikefarah.gitbook.io/yq/、Ubuntuにインストールする場合は、以下をyq使用してください。snap

yq eval '.client_encryption_options.enabled |= false' file.yml

...内部編集には対応する--inplaceオプションを使用してください。-i

yqファイルからコメントは削除されません。

おすすめ記事