The DCS grading programs — sorting options

Many of the grading programs allow you to re-order the student records in a grades file before processing them. Obviously you can do this with the actual sorting command, gsort, but others such as the "printing" command gpr are capable of reordering their output.

(However, gsort is the only one that actually reorders the student records in the grades file itself. For the other commands, it might be more appropriate to call these "indexing" options rather than "sorting" options.)

The sort key and direction are expressed through these command-line options:

-k sortkey
Use sortkey as the key when sorting. The key must have one of these values:
  • =: the sort key is the student name.
  • #: the sort key is the student number.
  • %: the sort key is the flag character.
  • markname: the sort key is the value of the mark named.
-r
Sort in reverse order. This option is ignored if the -k option is not present — except in the case of gsort, which assumes you want to sort by student name if you omit -k.

Examples

Suppose we're working with a grades file called "sortexample" containing these mark definitions and student records:

a1 / 10

1234567890    Alice	10
1234567891 d  Elena	5
1234567892  x Carla	0
1234567894    Brian	2
1234567893    David	4

As the base command — before the sorting options — we'll use "gpr -HTM", which prints the student records, without header, statistics or mark names.

Command: gpr -HTM sortexample
Output — the original ordering, because no sorting options were specified:

1234567890    Alice                10   
1234567891 d  Elena                5    
1234567892  x Carla                0    
1234567894    Brian                2    
1234567893    David                4    

Command: gpr -HTM -k= sortexample
Output — sorted by name:

1234567890    Alice                10   
1234567894    Brian                2    
1234567892  x Carla                0    
1234567893    David                4    
1234567891 d  Elena                5    

Command: gpr -HTM -k# sortexample
Output — sorted by student number:

1234567890    Alice                10   
1234567891 d  Elena                5    
1234567892  x Carla                0    
1234567893    David                4    
1234567894    Brian                2    

Command: gpr -HTM -ka1 -r sortexample
Output — sorted by a1 mark, in reverse order:

1234567890    Alice                10   
1234567891 d  Elena                5    
1234567893    David                4    
1234567894    Brian                2    
1234567892  x Carla                0    

Command: gpr -HTM -r sortexample
Output — the original ordering, because no key was specified, even though -r was set:

1234567890    Alice                10   
1234567891 d  Elena                5    
1234567892  x Carla                0    
1234567894    Brian                2    
1234567893    David                4