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.
More on awk, sed, grep and jq one-liners
Print only the lines containing "ERROR" with 3 lines of context, and show line numbers.BeginnerSum the response sizes (field 10) in an Nginx access log and print the total in MB.BeginnerReplace `DEBUG` with `INFO` in a config file in place, keeping a backup.BeginnerExtract all unique email addresses from a file.BeginnerFrom `kubectl get pods -A -o json`, list pods that are not Running, as namespace/name/phase.IntermediatePrint the 3rd column of a CSV whose fields are separated by commas, skipping the header.Beginner