使用query参数过滤组合AWS CLI输出信息
2015-08-17 17:59
417 查看
通常在使用CLI进行操作的时候,会输出很长一串json或表格文本在命令行端。
为了从这个输出信息中过滤出需要的信息,可能会用filter命令或者sed,grep,awk来处理。
AWS CLI本身支持query命令来使用复杂的语法来使用条件判断,过滤出需要的字段。
query本身的语法信息是通过JMESPath(http://jmespath.readthedocs.org/en/latest/specification.html)来定义的。
例如,普通使用“ aws devicefarm list-devices --region us-west-2”命令会输出形如
如果我们想找manufacturer是Apple的设备信息,可以使用
注意,这里的Apple是用反引号应用的,不是单引号,也不是双引号
输出
可以挑选一些参数来输出
注意,这4个参数是用方括号包围起来的。
使用
参数后,表格显示得就更易读了
aws devicefarm list-devices --region us-west-2 --query 'devices[?manufacturer==`Apple`].[name,resolution.width,resolution.height,os]' --output table
或者把输出信息使用json的map形式
注意命令行后面部分的大括号
输出
为了从这个输出信息中过滤出需要的信息,可能会用filter命令或者sed,grep,awk来处理。
AWS CLI本身支持query命令来使用复杂的语法来使用条件判断,过滤出需要的字段。
query本身的语法信息是通过JMESPath(http://jmespath.readthedocs.org/en/latest/specification.html)来定义的。
例如,普通使用“ aws devicefarm list-devices --region us-west-2”命令会输出形如
{ "devices": [ { "formFactor": "TABLET", "name": "Apple iPad Mini 2", "resolution": { "width": 1536, "height": 2048 }, "image": "NA", "platform": "IOS", "heapSize": 0, "memory": 17179869184, "model": "iPad Mini 2", "os": "7.1.2", "cpu": { "frequency": "MHz", "architecture": "ARMv8 (A32, A64)", "clock": 1400.0 }, "arn": "arn:aws:devicefarm:us-west-2::device:3B33A0062E6D47B4A50437C48F9141F6", "manufacturer": "Apple" }, { "formFactor": "TABLET", "name": "Apple iPod Touch 5th Gen", "resolution": { "width": 640, "height": 1136 }, "image": "NA", "platform": "IOS", "heapSize": 0, "memory": 68719476736, "model": "iPod Touch 5th Gen", "os": "8.1.2", "cpu": { "frequency": "MHz", "architecture": "ARMv7", "clock": 1200.0 }, "arn": "arn:aws:devicefarm:us-west-2::device:8BF08BA1178D4DF7B46AB882A62FFD68", "manufacturer": "Apple" }, 。。。 ] }
如果我们想找manufacturer是Apple的设备信息,可以使用
aws devicefarm list-devices --region us-west-2 --query 'devices[?manufacturer==`Apple`]'
注意,这里的Apple是用反引号应用的,不是单引号,也不是双引号
输出
[ { "formFactor": "TABLET", "name": "Apple iPad Mini 2", "resolution": { "width": 1536, "height": 2048 }, "image": "NA", "platform": "IOS", "heapSize": 0, "memory": 17179869184, "model": "iPad Mini 2", "os": "7.1.2", "cpu": { "frequency": "MHz", "architecture": "ARMv8 (A32, A64)", "clock": 1400.0 }, "arn": "arn:aws:devicefarm:us-west-2::device:3B33A0062E6D47B4A50437C48F9141F6", "manufacturer": "Apple" }, { "formFactor": "TABLET", "name": "Apple iPod Touch 5th Gen", "resolution": { "width": 640, "height": 1136 }, "image": "NA", "platform": "IOS", "heapSize": 0, "memory": 68719476736, "model": "iPod Touch 5th Gen", "os": "8.1.2", "cpu": { "frequency": "MHz", "architecture": "ARMv7", "clock": 1200.0 }, "arn": "arn:aws:devicefarm:us-west-2::device:8BF08BA1178D4DF7B46AB882A62FFD68", "manufacturer": "Apple" },
可以挑选一些参数来输出
aws devicefarm list-devices --region us-west-2 --query 'devices[?manufacturer==`Apple`].[name,resolution.width,resolution.height,os]'
注意,这4个参数是用方括号包围起来的。
[ [ "Apple iPad Mini 2", 1536, 2048, "7.1.2" ], [ "Apple iPod Touch 5th Gen", 640, 1136, "8.1.2" ], [ "Apple iPhone 5c", 640, 1136, "8.0.2" ], [ "Apple iPad Mini 1st Gen", 768, 1024, "7.1.2" ],
使用
--output table
参数后,表格显示得就更易读了
aws devicefarm list-devices --region us-west-2 --query 'devices[?manufacturer==`Apple`].[name,resolution.width,resolution.height,os]' --output table
------------------------------------------------------- | ListDevices | +---------------------------+-------+-------+---------+ | Apple iPad Mini 2 | 1536 | 2048 | 7.1.2 | | Apple iPod Touch 5th Gen | 640 | 1136 | 8.1.2 | | Apple iPhone 5c | 640 | 1136 | 8.0.2 | | Apple iPad Mini 1st Gen | 768 | 1024 | 7.1.2 | | Apple iPhone 6 | 750 | 1334 | 8.3 | | Apple iPhone 6 Plus | 1080 | 1920 | 8.1 | | Apple iPhone 6 | 750 | 1334 | 8.4 | | Apple iPad Air | 1536 | 2048 | 8.0 | | Apple iPhone 5 | 640 | 1136 | 8.1.1 | | Apple iPad Mini 1st Gen | 768 | 1024 | 8.4 | | Apple iPhone 5 | 640 | 1136 | 8.3 | | Apple iPhone 5c | 640 | 1136 | 8.3 | | Apple iPhone 5 | 640 | 1136 | 8.0 | | Apple iPhone 5s | 640 | 1136 | 7.1.2 |
或者把输出信息使用json的map形式
aws devicefarm list-devices --region us-west-2 --query 'devices[?manufacturer==`Apple`].{name:name,width:resolution.width,height:resolution.height,os:os}'
注意命令行后面部分的大括号
输出
[ { "width": 1536, "os": "7.1.2", "name": "Apple iPad Mini 2", "height": 2048 }, { "width": 640, "os": "8.1.2", "name": "Apple iPod Touch 5th Gen", "height": 1136 }, { "width": 640, "os": "8.0.2", "name": "Apple iPhone 5c", "height": 1136 },
相关文章推荐
- 使用nodejs开发cli项目实例
- php-cli简介(不会Shell语言一样用Shell)
- 通过PHP CLI实现简单的数据库实时监控调度
- php cli模式学习(PHP命令行模式)
- PHP CLI模式下的多进程应用分析
- php命令行(cli)下执行PHP脚本文件的相对路径的问题解决方法
- CLI添加一个控件
- PHP CLI模式下的多进程应用
- AWS上Mysql 的连接失败解决方式
- 使用AWS亚马逊云搭建Gmail转发服务(二)
- Amazon Simple Storage Service (Amazon S3)
- Amazon Elastic Compute Cloud (Amazon EC2)
- 学不进去、玩不痛快、睡不踏实、吃的还特多
- 讨厌这些不符合年龄而必须得去面对的经历
- AWS credential and creating EBS Snapshot(学习笔记)
- AWS AMI, Region and AZ
- 读AWS overview white paper 笔记
- AWS S3服务 笔记
- (三)Aws引用S3Client时候总是出现not found