Skip to content

Instantly share code, notes, and snippets.

@sloanlance
Last active September 29, 2023 14:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sloanlance/54749fa98ad4ff3ec8bf1a124f003315 to your computer and use it in GitHub Desktop.
Save sloanlance/54749fa98ad4ff3ec8bf1a124f003315 to your computer and use it in GitHub Desktop.
Useful notes about using yq

yq Notebook

Useful notes about using yq

  1. Display the path to each value in a YAML file

    $ cat << EOF | yq e '.. | select(. == "*") | {(path | join(".")): .} ' -
    > a:
    >   b: foo
    >   c: bar
    > EOF
    a.b: foo
    a.c: bar

    Explanation…

    • .. recursively select all values
    • select(. == "*") filter for scalar values (i.e. filter out the value of a)
    • (path | join(".")) gets the path as array and joins the elements with .
    • {…: .} create a mapping, having the joined paths as keys and their values as values

    From: https://stackoverflow.com/a/69303779/543738

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment