Interview Prep/Real-World Interview/awk, sed, grep and jq one-liners

Extract the value of a key from a YAML file in a shell script without Python.

IntermediateHands-onawk, sed, grep and jq one-liners
Answer
yq '.spec.template.spec.containers[0].image' deployment.yaml
# set a value in place (mikefarah yq v4)
yq -i '.spec.replicas = 3' deployment.yaml

Key trick → Use yq (the mikefarah Go binary), not grep | awk: YAML has nesting, multi-doc files and quoting that line tools get wrong.

All Real-World Interview questions Roadmap: Interview readiness

More on awk, sed, grep and jq one-liners