I have a file like aAbcI want to print number of times each line repeats it self in a case insensitive manner. I found below command to be useful:tr A-Z a-z | uniq -c | sed -e 's/^ *//' -e 's/ *$//'But it fails if the file is of form A \n  a. This gives 2 a. But the expected output is 2 AHow can I do that?
Count number of times each line repeats itself, In case Insensitive manner
bash;shell script
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:aAbcAaaAnd 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 -cisort with its -r option sorts Uppercase character as first rows. and with uniq and its -i option ignores differences in case.