Using hash table to count specific strings, and out put a result with time it repeat.File AAAABBBCCCDDDBBBDDDAAACCCBBBAAABBBCCCBBBResultAAA 3BBB 5CCC 3DDD 2
How to count specific strings in file?
shell script
Is this homework? If not, just use sort and uniq:$ sort file | uniq -c  3 AAA  5 BBB  3 CCC  2 DDDIf you need to script it yourself for some reason, you could use Perl:$ perl -lne '$k{$_}++; END{print $_\t$k{$_} for keys(%k)}'CCC 3BBB 5DDD 2AAA 3If you really need to use a shell script, you could do (here bash or ksh syntax):unset num;typeset -A num; while IFS= read -r line; do   ((num[$line]++))done < filefor line in ${!num[@]}; do   printf '%s\t%s\n' $line ${num[$line]}done