我的JSON输出看起来像这样;
{ "1":{ "state":{ "on":false, "bri":124, "hue":14985, "sat":252, "effect":"none", "xy":[ 0.5182, 0.4363 ], "ct":480, "alert":"none", "colormode":"xy", "reachable":true }, "type":"Extended color light", "name":"Slaapkamer rechts", "modelid":"LCT001", "manufacturername":"Philips", "uniqueid":"00:17:88:01:00:dc:36:68-0b", "swversion":"66013187" }, "2":{ "state":{ "on":false, "bri":125, "hue":14984, "sat":252, "effect":"none", "xy":[ 0.5182, 0.4363 ], "ct":480, "alert":"none", "colormode":"xy", "reachable":true }, "type":"Extended color light", "name":"Slaapkamer links", "modelid":"LCT001", "manufacturername":"Philips", "uniqueid":"00:17:88:01:00:dc:33:99-0b", "swversion":"66013187" } }
有谁知道一个简单的方法来使这个输出grep-able?或者将输出放在一行上的任何其他方法,以便我可以在json输出上使用像grep,awk等工具?如果我现在在'hue'这个词上做一个grep然后我得到2行;
"hue":14985, "hue":14984,
虽然我有时只想在第一个或第二个上涂鸦.
有任何想法吗?
用jq
:
jq '.["1"].state.hue' file
输出:
14985
不可能使用,'.1.state.hue'
因为数字是一种特殊情况.
jq '.["2"].state.hue' file
输出:
14984
jq '.[].state.hue' file
输出:
14984 14985