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

When should you use the AWS CLI's `--query` instead of piping to `jq`?

IntermediateConceptfind, xargs, jq and yq
Answer

--query uses JMESPath and runs inside the CLI, so there is no extra dependency, and --output text gives tab-separated values ready for read.

aws ec2 describe-instances \
  --filters Name=tag:Env,Values=prod Name=instance-state-name,Values=running \
  --query 'Reservations[].Instances[].[InstanceId,PrivateIpAddress]' --output text |
  while read -r id ip; do echo "$id $ip"; done

Use jq for complex transformations, joins, or when the same script handles output from other tools. kubectl has a similar option with -o jsonpath='{.items[*].metadata.name}'.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on find, xargs, jq and yq