External sort is the pattern
Sort what fits, write it out, merge the sorted pieces. The same merge that powers merge sort now works across files.
Read once if you can
If a single pass plus a small amount of state is enough, avoid sorting at all. Counting or bucketing can order data without comparisons.