This will do the trick:
$ awk '!a[$0]++{u[$1]++}END{for (k in u) print k,u[k]}' file
AA 3
AB 2
AC 1
XX 1
To ensure sorted output pipe to sort -rnk2
for a reverse numerical sort on the second field:
$ awk '!a[$0]++{u[$1]++}END{for (k in u) print k,u[k]}' file | sort -rnk2
AA 3
AB 2
XX 1
AC 1
Explanation:
We keep a count of all the unique lines in the associative array a
and only update the secondary array u
if we haven't seen the current line before.