I have a bash script that pushes different width:height values onto the end of an array. Some of the values are duplicates. What I need to do is loop through the array, count the number of occurrences for each unique value in the array and then retrieve the value with the most duplicates.
dimensions=( )
dimensions[${#dimensions[*]}]="450:180"
dimensions[${#dimensions[*]}]="360:240"
dimensions[${#dimensions[*]}]="360:240"
dimensions[${#dimensions[*]}]="640:480"
dimensions[${#dimensions[*]}]="360:240"
dimensions[${#dimensions[*]}]="640:480"
In the array above I would need to retrieve the value "360:240" since there were 3 duplicates. How can I count the unique values and end up with a variable containing the value with the most duplicates from the array?
mostDuplicates="360:240"