I have an array of value,location
pairs
arr=(test,meta my,amazon test,amazon this,meta test,google my,google hello,microsoft)
I want to print the duplicate values, the number/count of them, along with the location.
For example:
3 test: meta, amazon, google
2 my: amazon, google
1 this: meta
1 hello: microsoft
Here test
appears 3 times, in meta
, amazon
, and google
So far, this code will print the item and location
printf '%s\n' "${arr[@]}" | awk -F"," '!_[$1]++'
test,meta
my,amazon
this,meta
hello,microsoft
This will print the count, but it's taking in the value,location
as one value
printf '%s\n' "${arr[@]}" | sort | uniq -c | sort -r
1 my,amazon
1 my,google
1 this,meta
1 test,meta
1 test,google
1 test,amazon
1 hello,microsoft