How to sort lines of text
- Paste your list into Lines to sort, one item per line. Clear text empties the box.
- Choose Sort by: alphabetical, numerical, length, reverse the current order, or random shuffle.
- Set the options: Trim spaces around each line, Remove blank lines, Remove duplicates, Ignore upper and lower case and Natural order (2 before 10).
- Press Copy sorted lines. In random mode, Shuffle again gives a new order.
How each sort works
The tool trims, removes blank lines and removes duplicates first (keeping the first copy of each line), then sorts what is left. If you untick Remove blank lines, the blank lines sort to the top.
- Alphabetical: with Ignore upper and lower case on, lines follow your browser's dictionary order, so Apple and apple sit together and accents sort next to their base letter. With it off, lines follow strict character-code order, where every capital letter comes before every lowercase one (Z before a). Natural order reads runs of digits as whole numbers, so item 2 comes before item 10.
- Numerical: uses the first number in each line. Thousands commas are ignored (1,000 is one thousand), currency symbols are skipped, and a minus sign counts only when it stands alone, so -4 is negative but the dash in file-5 is not. Lines with no number come after the numbered ones, in alphabetical order, and equal numbers are ordered alphabetically.
- Length: counts characters, so an emoji counts once, and breaks ties alphabetically.
- Random shuffle: a Fisher-Yates shuffle using your browser's random number generator, so every order is equally likely.
Worked example
The sample list has six lines: banana, apple, cherry, date, apple, elderberry. With the defaults (Alphabetical, Trim, Remove blank lines, Ignore case and Natural order on) the tool shows "6 lines in, 6 lines out." and:
apple apple banana cherry date elderberry
Tick Remove duplicates and the second apple goes, giving "6 lines in, 5 lines out. Removed 1 duplicate." For prices, the lines $30, $5, $120 and $7 sort by Numerical (low to high) into $5, $7, $30 and $120.
Limits and edge cases
Numerical sorting reads only the first number, so 2024-05-06 sorts as 2024, and a period is always the decimal point, so 1.234,56 is read as 1.234. For ISO dates use Alphabetical. Dictionary order follows your browser's language, so letters such as ΓΆ can sort differently in Swedish and German. The text stays in your browser and is not uploaded. To reverse only the order of the lines use the Text Reverser, to number the sorted result use the Line Number Adder, and for duplicates alone try the Duplicate Line Remover.
Frequently asked questions
How do I alphabetize a list?
Paste the list into Lines to sort, leave Sort by on Alphabetical (A to Z) and copy the result. Tick Remove duplicates if the list repeats items.
Why does 10 sort before 2?
Plain alphabetical sorting compares one character at a time, and 1 comes before 2. Keep Natural order ticked so digits are read as whole numbers and item 2 comes before item 10.
How do I sort numbers with commas or dollar signs?
Choose Numerical (low to high). The sorter ignores thousands commas and currency symbols, so $5, $7, $30 and $120 sort in that order and 1,000 counts as one thousand.
How do I remove duplicates while sorting?
Tick Remove duplicates. The first copy of each line is kept, and with Ignore upper and lower case ticked, Apple and apple count as the same line.
Is the shuffle really random?
It is a fair shuffle: every order is equally likely. The tool uses a Fisher-Yates shuffle driven by your browser's random number generator, and Shuffle again gives a new order.