Rome_Leader Rome_Leader - 3 months ago 12
JSON Question

Bash Parsing JSON name after sorting

I'm trying to get the most recent (highest number prefix) CacheClusterId from my Elasticache using the AWS CLI in order to put it into a Chef recipe. This is what I've got so far:

aws elasticache describe-cache-clusters --region us-east-1 | grep CacheClusterId | sort -t : -rn


Which produces:

"CacheClusterId": "xy112-elasticache"
"CacheClusterId": "xy111-elasticache"
"CacheClusterId": "xy110-elasticache"
"CacheClusterId": "xy109-elasticache"
"CacheClusterId": "xy-elasticache"


How can I isolate just the "xy112-elasticache" portion (minus quotes)? Having read the man page for sort, I feel like it requires a
-k
option, but I haven't been able to work out the particulars.

Fma Fma
Answer

Since first part is same for all I will just cut them and take id part in following way:

aws elasticache describe-cache-clusters --region us-east-1 | grep CacheClusterId | cut -d'"' -f4