Many of the grading programs allow you to re-order the student records in a grades file before processing them. This applies not only to the actual sorting command, gsort, but also to others such as the output command gpr.
(However, gsort is the only one that actually re-orders the student records in the file. For the other commands, it might be more appropriate to call these "indexing" options rather than "sorting" options.)
You state your sorting requirements by means of command-line options, and this page describes the options that are available.
Here are the available command-line options:
The sorting options in the new version of the grading programs are the same as in the old version, though they are accepted by more of the programs than formerly.