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

Update a value inside a JSON file with jq (set `.replicas` to 5) and write it back.

IntermediateHands-onawk, sed, grep and jq one-liners
Answer
jq '.replicas = 5' config.json > config.json.tmp && mv config.json.tmp config.json
# with a shell variable
jq --argjson n "$REPLICAS" '.replicas = $n' config.json > tmp && mv tmp config.json

Key trick → jq ... > config.json truncates the file before jq reads it, so always go through a temp file. Use --argjson for numbers and --arg for strings.

All Real-World Interview questions Roadmap: Interview readiness

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