Hello neszt76 and welcome to PerlMonks. We use Perl here.
perl -nE '$f.=$_}{$t{$_}=()=$f=~/\Q$_/g for $f=~/^sub\s+(\w+)/gm;say " +$t{$_} $_" for sort {$t{$b} <=> $t{$a}} keys %t;' $FILE
This uses precisely* the same logic as your shell loop above (and therefore has the same algorithmic flaws). Nonetheless, advantages of the Perl approach include:
Enjoy.
*Not precisely: there's one trivial fix to avoid lines which start with eg. "submarine".
In reply to Re^2: Cleaning up unused subroutines
by hippo
in thread Cleaning up unused subroutines
by koknat
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |