in reply to homework: Simple matching and sorting
perl -ne '$,{$_}++for/(?:[\x27\w]+|-(?!--))+/g; END{for(sort{$,{$a}<=>$,{$b}}keys(%,)){printf"%4d: %s\n",$,{$_},$_}}' +file.txt [download]