![jq + 如何仅打印属性下键的值](https://linux22.com/image/137963/jq%20%2B%20%E5%A6%82%E4%BD%95%E4%BB%85%E6%89%93%E5%8D%B0%E5%B1%9E%E6%80%A7%E4%B8%8B%E9%94%AE%E7%9A%84%E5%80%BC.png)
我们有以下 json 文件
more t.json
{
"href" : "htr",
"items" : [
{
"href" : "lpo",
"tag" : "version1533203561827110",
"type" : "kafka-log4j",
"version" : 6,
"Config" : {
"cluster_name" : "hdp",
"stack_id" : "HDP-2.6"
},
"properties" : {
"content" : "Licensed to the Apache Software Foundation",
"controller_log_maxbackupindex" : "20",
"controller_log_maxfilesize" : "256",
"ey=log4j.rootLogger" : "DEBUG",
"ey=properties.content" : "DEBUG",
"kafka_log_maxbackupindex" : "20",
"kafka_log_maxfilesize" : "256"
}
}
]
}
我们只想打印内容的值
jq '.items[].properties | to_entries[] | " \(.value)"' t.json
" Licensed to the Apache Software Foundation"
" 20"
" 256"
" DEBUG"
" DEBUG"
" 20"
" 256"
但它打印所有其他值
我哪里错了,我应该纠正什么?
预期产出
" Licensed to the Apache Software Foundation"
答案1
尝试这个,
jq '.items[].properties.content' t.json
-r
如果您想去掉双引号,请添加