我试图从我的Elasticache中使用AWS CLI获取最新(最高号码前缀)CacheClusterId,以便将其放入Chef配方中。这是我到目前为止有:Bash在排序后解析JSON名称
aws elasticache describe-cache-clusters --region us-east-1 | grep CacheClusterId | sort -t : -rn
主要生产:
"CacheClusterId": "xy112-elasticache"
"CacheClusterId": "xy111-elasticache"
"CacheClusterId": "xy110-elasticache"
"CacheClusterId": "xy109-elasticache"
"CacheClusterId": "xy-elasticache"
我如何可以隔离只是 “xy112-elasticache” 部分(减去引号)?阅读手册页进行排序,我觉得它需要一个-k
选项,但我无法解决详细情况。
有趣。我是否也可以使用剪切来抓取最高记录?这是我感兴趣的唯一一个。现在,我的输出与上面(多条记录)相同,但没有CacheClusterId部分和引号。 –
如果它始终是最高记录,您可以将结果剪切到'head -n 1' – Fma