json;重复键并根据值进行过滤

时间:2018-10-16 16:29:55

标签: jq

尝试基于addrtype过滤json,如果addraddrtype,则打印ipv4;如果vendor为{{1},则打印addrtype }。

到目前为止,我有mac会导致:

'"\(.addr) \(.addrtype) \(.vendor)"'

所需结果:

"192.168.1.235 ipv4 null"
"18:B4:30:8D:AE:BA mac Nest Labs"
"192.168.1.236 ipv4 null"
"18:B4:30:8D:B6:18 mac Nest Labs"
"192.168.1.238 ipv4 null"
"0C:EA:C9:AF:4F:72 mac null"
"192.168.1.254 ipv4 null"
"0C:EA:C9:AF:4F:70 mac null"

数据:

192.168.1.235 - Nest Labs
192.168.1.236 - Nest Labs
192.168.1.238 - 
192.168.1.254 - 

1 个答案:

答案 0 :(得分:1)

这将产生所需的结果:

jq -sr '.[] | "\(.[0].addr) - \(.[1].vendor//"")"' file