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 파일이므로 yq다음 과 같은 명령줄 YAML 파서를 사용할 수 있습니다.https://kislyuk.github.io/yq/

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

이렇게 하면 최상위 개체 enabled의 키 값이 로 업데이트됩니다 .client_encryption_optionsfalse

현재 위치에서 변경하려면 yq해당 --in-place또는 -i옵션과 함께 사용하세요.

이는 JSON 래퍼를 yq둘러싼 래퍼 jq이므로 문서에서 주석을 제거합니다.


yq에서 프로그램을 사용하는 경우https://mikefarah.gitbook.io/yq/, 예를 들어 Ubuntu를 yq사용하여 설치하면 얻을 수 있는 것입니다.snap

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

... 내부 편집을 수행하려면 해당 --inplace또는 옵션을 사용하세요.-i

yq파일에서 주석은 제거되지 않습니다 .

관련 정보