Set (or overwrite) a key to a value in a file (v4+)

yq

  • A lightweight and portable command-line YAML processor.
    More information: <https://mikefarah.gitbook.io/yq/>.
  • Trick copyright: tl;dr; <https://github.com/tldr-pages/tldr>

yq eval '.{{key}} = "{{value}}"' --inplace {{path/to/file.yaml}}

click the source code to copy install yq on any operating system with command-not-found.com