Interview Prep/Shell Scripting/find, xargs, jq and yq

What is `yq`, and why does "which yq" matter?

IntermediateConceptfind, xargs, jq and yq
Answer

Two different tools share the name:

  • mikefarah/yq (Go, v4): jq-like syntax for YAML, JSON, XML, TOML, with in-place editing (-i) that preserves comments. This is the common one in DevOps.
  • kislyuk/yq (Python): a wrapper that converts YAML to JSON and runs real jq.
yq --version          # "yq (https://github.com/mikefarah/yq/) version v4.x"
yq '.spec.replicas' deploy.yaml
yq -i '.spec.replicas = 3' deploy.yaml

Pin the exact tool and version in CI images, because scripts written for one fail with the other (and yq v3 syntax yq r file key fails in v4).

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on find, xargs, jq and yq