Sort output by partition