This is an old revision of the document!
Excellent examples of jq filters : https://github.com/ipspace/docker-examples/tree/d8599f8b4e44b24cc50afafd8a56438ab31bf80b/filter
jq . # the dots means 'applies for all objects below'
aws ec2 describe-regions | jq -r "[[.Regions[].RegionName]]" aws ec2 describe-vpcs | jq -r "[[.Reservations[].Instances[].InstanceId]]" # extract all instances id (down 3 levels) aws ec2 describe-vpcs | jq -r '.Vpcs | length' # COUNT number of VPCs aws ec2 describe-vpcs --region eu-west-1 | jq -r '.Vpcs | length' # For a DIFFERENT Region
Lists the public IPs (querying the OCI DNS):
oci dns record zone get --zone-name-or-id oci.mycompany1.co.uk | jq -r '.[].items[] | .domain + " " + .rdata' oci dns record zone get --zone-name-or-id lhr.oci.mycompany1.co.uk | jq -r '.[].items[] | .domain + " " + .rdata' oci compute instance get --instance-id ocid1.instance.oc1.uk-london-1.anwgiljrgghpcsic6lrm3u5zqh7vwqqvsv44ewyjybis3lzhhb7bqmizelrq | jq -r '.data | .["display-name"]' # how to extract the keys that OCI annoying put hyphens in rather than underscores oci network vcn list --region=eu-frankfurt-1 --compartment-id=$cs | jq -r '.data[] | .["compartment-id"]'
Folsom:
cat /home/jaime/Downloads/response.json | jq -r '.response[].attributes | .display_name ' > /home/jaime/Downloads/response1.json
oci compute instance list --compartment-id=$cb | jq -r '.data[]|select (."display-name"=="pepe37.lhr.oci.mycompany1.co.uk")'
oci compute instance list --compartment-id=$cb | jq -r '.data[]|select (."display-name" | contains("cc0"))' # like regex 'contains'
This filters with id but extracts the pair, not the key https://til.hashrocket.com/posts/uv0bjiokwk-use-jq-to-filter-objects-list-with-regex
oci network nsg list --region us-phoenix-1 --compartment-id ocid1.compartment.oc1..aaaaaaaax5zpuw6ggeudpiqueidy5xlqentk2ngs7p6445an34mgwlrpbccq | jq -r '.data[] | ."defined-tags"."NetworkSecurity"."groupId" + ": " + .id'
Formatted output with my own labels External Link:
.[]|{
Name, Gateway: .IPAM.Config[]|.Gateway,
Endpoints: [
.Containers|to_entries[]|{
Name: .value.Name, IPv4: .value.IPv4Address }
]
}
docker network inspect bg0 | jq -f myfilterabove