我有一个 json 文件,其中包含大量 AWS CloudWatch 日志(从 CLI 命令生成)。我正在尝试使用 jq仅返回没有“retentionInDays”字段的条目的值。我有以下内容,可以根据需要返回所有内容,但我似乎无法过滤掉确实具有保留时间的结果。
# Working output (unfiltered)
jq ".logGroups[] | { log_name: .logGroupName, log_arn: .arn, retention_scheme: .retentionInDays }" cwlogs.json
我已经尝试了几件事,但要么得到错误,要么完成并且什么也不输出:
# Doesn't return anything
jq '.logGroups[] | { log_name: .logGroupName, log_arn: .arn, retention_scheme: select(.retentionInDays | contains ("null")?) }' cwlogs.json
# Errors with "jq: error (at cwlogs.json:760): number (7) and string ("null") cannot have their containment checked"
jq '.logGroups[] | { log_name: .logGroupName, log_arn: .arn, retention_scheme: select(.retentionInDays | contains ("null")) }' cwlogs.json
# Hangs forever
jq '.logGroups[] | select(.retentionInDays != "null").type'
更新:我正在使用的 JSON 的可测试段
{
"logGroups": [
{
"storedBytes": 0,
"metricFilterCount": 0,
"creationTime": 1234,
"logGroupName": "/aws/elasticbeanstalk/docker",
"retentionInDays": 7,
"arn": "longarnhere"
},
{
"storedBytes": 0,
"metricFilterCount": 0,
"creationTime": 1245,
"logGroupName": "/aws/elasticbeanstalk/nginx",
"arn": "longarnhere"
}
]
}