I have a variable in script shell, when I execute echo $myvariable. this is the output :
{"networks":[{"status":"ACTIVE","router:external":true,"availability_zone_hints":[],"availability_zones":["nova"],
"ipv4_address_scope":null,"description":"",
"port_security_enabled":true,**"subnets":["56efe610-32af-4f03-a73d-14bcbf1c9ae1","18ca945c-8868-4549-b725-e11f04612663"],**
"updated_at":"2018-02-26T04:55:25Z",
*"tenant_id":"187d635aec4c43fe8e8918afb3a5c82e",*
"created_at":"2018-02-26T04:55:12Z",
"tags":[],"ipv6_address_scope":null,
"mtu":1500,"is_default":true,"revision_number":7,
"admin_state_up":true,"shared":false,
"project_id":"187d635aec4c43fe8e8918afb3a5c82e",
"id":"7697d4c6-5b4c-4ea9-a1d6-af7d7f716f2b","name":"public"
Then I'm trying to extract the subnet id (56efe610-32af-4f03-a73d-14bcbf1c9ae1 and 18ca945c-8868-4549-b725-e11f04612663)
and the tenant_id (187d635aec4c43fe8e8918afb3a5c82e
).
I tried for tenant_id this shell script:
tenantid=$("$myvariable" | grep "tenant_id" | awk '{printf $2}')
echo $tenantid I get the same result.
For the subnets, I tried the same but I have same result.
subnets=$(echo "$myvariable" | grep "subnets" | awk '{printf $1}')
Thanks in advance guys.