Sort & Number Lines
Sort, number, reverse, or shuffle lines of text.
Last updated: August 2026
Was this tool helpful?
Sorting, numbering, and shuffling lines
This handles the structural moves on a list of lines: sort them, prefix each with a line number, reverse the order, or shuffle into a random order. Each is a distinct operation, and sorting in particular has more depth than it first appears.
Lexicographic vs natural sort
Plain sorting compares character codes, so item10 lands before item2 because 1 sorts before 2. Natural sort reads embedded numbers as numbers, giving the order a human expects. If your list has filenames or versions with numbers in them, the difference is glaring.
Example
Lexicographic Natural
file1 file1
file10 file2
file2 file10Case matters too. ASCII sorting puts all uppercase letters before lowercase, so Zebra comes before apple unless you sort case-insensitively.
Numbering and shuffling
Numbering is useful for referencing lines in a review or generating a quick ordered list. A fair shuffle should use the Fisher-Yates algorithm; naive approaches like sorting by a random key are subtly biased and skew the distribution. Shuffling is handy for randomizing quiz questions or sampling.
FAQ
Why is item10 before item2 after sorting? That is lexicographic order comparing digit by digit. Switch to natural sort to treat the numbers as values.
Does sorting remove duplicates? No, sorting only reorders. To drop repeats, run a duplicate line remover afterward.
Will a blank line sort to the top? Usually yes, an empty string sorts before any text, so trailing blank lines can jump to the front unexpectedly.