Skip to content

Instantly share code, notes, and snippets.

@res0nat0r
Last active December 19, 2020 00:06
Show Gist options
  • Save res0nat0r/ed0b3884b600080dcd962b02cc91e5f7 to your computer and use it in GitHub Desktop.
Save res0nat0r/ed0b3884b600080dcd962b02cc91e5f7 to your computer and use it in GitHub Desktop.
Useful JQ Examples

  • Print VPC Matching Name:
 aws ec2 describe-vpcs --out json | jq '.Vpcs[] | {VPC:(.Tags[] | select(.Key=="Name").Value), CIDR:.CidrBlockAssociationSet[].CidrBlock}'
  • List all VPC's and their CIDR Blocks:
aws ec2 describe-vpcs --out json | jq '.Vpcs[] | (.Tags[] | select(.Key=="Name").Value), .CidrBlockAssociationSet[].CidrBlock'
  • Sum items:
$ cat archive.json | jq -s 'map(.Contents[].Size) | add'
  • TSV Output:
aws s3api list-objects-v2 --bucket bucket --prefix prefix --out json | jq -r '.Contents[] | [.Key, .Size] | @tsv'
  • Return only items matching prefix:
cat files.json | jq -r '.Contents[] | select(.Key|test("^prefix_to_match"))'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment