I have strings extracted from jq , from which I just want to get unique values.
"a-b-c-v001"
"a-b-c-v002"
"a-b-c-v001"
"a-b-c-v003"
"a-b-c-v002"
I just need 3 results, unique
"a-b-c-v001"
"a-b-c-v002"
"a-b-c-v003"
I have tried unique & sort did not work - https://jqplay.org/s/xjND6Iv60T
Make sure your jq expression produces an array. For example, if your jq expression (the one producing a stream of strings) is E, then you could modify it to:
[E] | unique | .[]
or just:
[E] | unique[]
unique
involves a sort, which can easily be avoided if E as above produces a stream of strings:
INDEX(E;.)[]
So, in answer to a Q in a comment, a sort-free way to get the count of distinct strings would be:
def count(s): reduce s as $x (0;.+1);
count( INDEX(E;.)[] )