First of all you have to use sort
command before using uniq -c
because this command fails if you have another repeated characters after other characters like input:
a
A
b
c
A
a
a
And second problem you get wrong result because you convert all uppercase to lowercase, it cause you getting result in lowercase.
Also you don't need 's/ *$//'
part of sed because your output has no spaces on end of lines.
You should try with your modified command as this:
tr a-z A-Z <file |sort | uniq -c | sed 's/^ *//'
Or even shorter try:
sort -r file |uniq -ci
sort
with its -r
option sorts Uppercase character as first rows. and with uniq
and its -i
option ignores differences in case.