【发布时间】:2015-07-09 01:27:26
【问题描述】:
我使用以下 JQ 命令过滤掉 JSON。如果存在预期的节点,我的要求是过滤掉 JSON 消息。否则,什么也不做。因此,我使用 if, elif, ....
sed -n "s/.*Service - //p" $1/response.log* |
jq "if (.requests | length) != 0 then .requests |= map(select(.id == \"123\"))
elif (.result | length ) != 0 then .result |= map(select(.id== \"123\"))
else " " end" > ~/result.log
看起来 else 在这里是强制性的。我不想在 else 块内做任何事情。无论如何,我可以忽略 else 或者只是在 else 中打印一些 whitespce。
在上述情况下,它会在结果文件中打印双引号“”。
【问题讨论】:
标签: json if-statement syntax jq