in reply to homework: Simple matching and sorting

  1. perl -ne '$,=$_if/;/END{print$,}' file.txt
  2. perl -ne '$,{$_}++for/(?:[\x27\w]+|-(?!--))+/g; END{for(sort{$,{$a}<=>$,{$b}}keys(%,)){printf"%4d: %s\n",$,{$_},$_}}' +file.txt
I didn't test the first one, but I did test the second.