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

Using jq, get the list of EC2 instance IDs and private IPs that are in "running" state.

IntermediateHands-onawk, sed, grep and jq one-liners
Answer
aws ec2 describe-instances --filters Name=instance-state-name,Values=running \
  | jq -r '.Reservations[].Instances[] | [.InstanceId, .PrivateIpAddress] | @tsv'

Or with the built-in JMESPath: --query 'Reservations[].Instances[].[InstanceId,PrivateIpAddress]' --output text.

Key trick → Instances are nested under Reservations, so you need .Reservations[].Instances[]. @tsv gives clean columns.

All Real-World Interview questions Roadmap: Interview readiness

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