How to extract the IP address of the output of the gcloud
command mentioned bellow?
The goal is to extract the IP_ADRESS where TARGET contains targetPools
and store it in a variable.
$ gcloud compute forwarding-rules list
>output:
NAME: abc
REGION: us
IP_ADDRESS: 00.000.000.000
IP_PROTOCOL: abc
TARGET: us/backendServices/abc
NAME: efg
REGION: us
IP_ADDRESS: 11.111.111.111
IP_PROTOCOL: efg
TARGET: us/targetPools/efg
desired output:
IP="11.111.111.111"
my attempt:
IP=$(gcloud compute forwarding-rules list | grep "IP_ADDRESS")
it doesn't work bc it need to
- get the one with TARGET contains
targetPools
- extract the IP_ADRESS
- store in local variable to be used
But not sure how to do this, any hints?