这是Json:我试着用
jq -r '.[] | .DBSnapshotIdentifier'但对我来说不管用
{
"DBSnapshots": [
{
"DBSnapshotIdentifier": "auto-lims-final-snapshot",
"DBInstanceIdentifier": "auto-lims",
"SnapshotCreateTime": "2018-08-15T09:59:23.332000+00:00",
"Engine": "postgres",
"AllocatedStorage": 50,
"Status": "available",
"Port": 5432,
"AvailabilityZone": "us-east-2a",
"VpcId": "vpc-e799fc8f",
"InstanceCreateTime": "2018-04-09T08:28:03.565000+00:00",
"MasterUsername": "postgres",
"EngineVersion": "9.6.6",
"LicenseModel": "postgresql-license",
"SnapshotType": "manual",
"OptionGroupName": "default:postgres-9-6",
"PercentProgress": 100,
"StorageType": "gp2",
"Encrypted": false,
"DBSnapshotArn": "arn:aws:rds:us-east-2:833682533595:snapshot:auto-lims-final-snapshot",
"IAMDatabaseAuthenticationEnabled": false,
"ProcessorFeatures": [],
"DbiResourceId": "db-ZL5T2TA2PJVG6CVOJRO7HUOAXQ",
"TagList": [
{
"Key": "Environment",
"Value": "auto"
},
{
"Key": "Application",
"Value": "LIMS"
}
],
"SnapshotTarget": "region"
},
{
"DBSnapshotIdentifier": "automation-lims-before-postgres-12-5",
"DBInstanceIdentifier": "automation-lims",
"Engine": "postgres",
"AllocatedStorage": 500,
"Status": "available",
"Port": 5432,
"AvailabilityZone": "us-east-2b",
"VpcId": "vpc-09fa88d2884ee2083",
"InstanceCreateTime": "2019-12-26T11:19:41.947000+00:00",
"MasterUsername": "lims",
"EngineVersion": "9.6.20",
"LicenseModel": "postgresql-license",
"SnapshotType": "manual",
"OptionGroupName": "default:postgres-9-6",
"PercentProgress": 100
}
]
}我怎么能只得到嵌套行。
发布于 2021-12-07 14:11:36
首先需要选择DBSnapshots对象,尝试:
.DBSnapshots[] | .DBSnapshotIdentifier这将产生以下结果:
"auto-lims-final-snapshot"
"automation-lims-before-postgres-12-5"您可以尝试使用in this online demo
要包含.TagList.Key,我们可以添加以下内容:
.DBSnapshots[] | .DBSnapshotIdentifier, .TagList[]?.Key现在这将输出
"auto-lims-final-snapshot"
"Environment"
"Application"
"automation-lims-before-postgres-12-5"您可以尝试使用in this online demo
如果您希望DBSnapshotIdentifier与TagList位于同一条线上,我们可以使用字符串插值,如下所示:
.DBSnapshots[] | "\(.DBSnapshotIdentifier) - \(.TagList[]?.Key)"Thiis将输出:
"auto-lims-final-snapshot - Environment"
"auto-lims-final-snapshot - Application"上面命令中的.[]?表示:
与
.[]类似,但是如果.不是数组或对象,则不会输出错误。
https://stackoverflow.com/questions/70261491
复制相似问题