given the following json, how could i create a tsv, that would output the frequencies of the values found in it (in the new element)?
{"_id":{"$someid":"545"},"new":"813 ROT","old":{"$someid":"5fe"}}
{"_id":{"$someid":"659889a"},"new":"9878 SU","old":{"$someid":"5bc"}}
{"_id":{"$someid":"986978754b"},"new":"813 ROT","old":{"$someid":"5bc1af"}}
desired output:
813 ROT 2
9878 SU 1
i can extract the values with .new, but do not know how to group them and create the tsv then
what i have tried:
def counter(stream): reduce stream as $s ({}; .[$s|tostring] += 1); counter(inputs | .new) | to_entries[] | {ItemId: (.key), Count: .value}
but gives output:
{
"ItemId": "9878 SU",
"Count": 1
}
{
"ItemId": "813 ROT",
"Count": 1
}
i use version of jq found in ubuntu 16.04 repositories