Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vadirajks/105734b2eeea5caa60012c6daa0a907e to your computer and use it in GitHub Desktop.
Save vadirajks/105734b2eeea5caa60012c6daa0a907e to your computer and use it in GitHub Desktop.
sort the fields from the gcloud compute instances list command
list_vm_gcp() {
gcloud compute instances list --project $1 '--format=json(NAME:sort=0,ZONE:sort=1,MACHINE_TYPE,PREEMPTIBLE,INTERNAL_IP,EXTERNAL_IP,STATUS,creationTimestamp:sort=2)' | jq -r '.[] |[.name, (.zone | split("/")[-1]), (.machineType | split("/")[-1]), .scheduling.preemptible, .networkInterfaces[0].networkIP, (.networkInterfaces[0].accessConfigs[0].natIP // "N/A"), .status, .creationTimestamp] | @tsv'| sort -t$'\t' -k8,8 -k2,2 -k1,1 | column -t
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment