我使用以下JQ命令过滤掉JSON.我的要求是,如果存在预期的 node ,则过滤掉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
看起来其他的都是强制性的.我不想在其他挡路里面做任何事情.不管怎么说,我可以忽略其他内容,或者在其他内容中打印一些空格.
在上述情况下,它会在结果文件中打印双引号"".