In a shell script using bash i would like to find the most frequent occurrence of a number within an array and store the result in variable $result. The array could have any number of values. If multiple results are returned then I would like to select the lowest number.
I understand bash may not be the best tool for this and I am open to suggestions using tools available from the command line within my script on a Mac OS X system.
Example:
array=(03 03 03 04 04 04 04)
3 occurrences of 03
4 occurrences of 04
Should return 04 into a variable named $result.
Another example:
array=(03 03 03 03 04 04 04 04)
4 occurrences of 03
4 occurrences of 04
Select lowest number which is 03
Should return 03 into a variable named $result.
Thank you for your help.