This thing can be done using Perl one liner command:
perl -le 'while(<>){$h{$1}++ if m/^(\S+)#?/} print "$_ #$h{$_}" for keys %h' input.txt
This is reading the file line by line and saving the names into a Hash. After that it just prints the keys from the hash with a count.