Toolstia / Sort lines alphabetically
Sort lines of text
Sorting a list sounds trivial until the list has capital letters, accents, numbers and blank lines. This tool sorts any text one line at a time. It offers plain alphabetical order, a natural order in which numbers inside the text are compared as numbers, sorting by the number at the start of the line, sorting by length, reversing the current order and shuffling at random. Each mode can be combined with options for trimming spaces and removing empty lines.
People use it for name lists, tag lists, glossary entries, keyword exports, file names, to-do lists and CSV columns pasted from a spreadsheet. If you only need one column ordered, paste it and copy the result back. The sorting happens locally in your browser, so private lists, such as customer names, are not sent anywhere.
How it works
- Paste your lines.
- Choose how to sort.
- Copy the sorted list.
Alphabet and natural order
Plain alphabetical order puts file10 before file2 because it compares one character at a time. Natural order reads the digits as numbers, so file2 comes before file10. Both follow your language's rules for accents.
Sorting by number
Each line is read for the number at its start, and commas like 1,000 are understood. Lines that do not begin with a number go to the end in their original order.
Descending, reverse and shuffle
Descending flips the chosen sort. Reverse simply flips the existing order without sorting. Shuffle puts lines in a random order and can be repeated.
Duplicates
Sorting keeps every line. To remove repeated lines too, use the remove duplicate lines tool.
Same list, different modes
Take the lines file10.txt, file2.txt and file1.txt. Alphabetical order gives file1.txt, file10.txt, file2.txt, because the characters 1 and 0 in 10 come before the 2. The natural mode gives file1.txt, file2.txt, file10.txt, which is the order people expect, because it reads the digit runs as whole numbers.
Use alphabet mode for words and natural mode for anything with numbers inside: version labels, chapter titles, room numbers and product codes. If your lines start with a number, the number-at-the-start mode is the better choice.
What happens with upper and lower case
By default the case is ignored, so apple, Apple and banana sort next to each other. With the list banana, Apple, cherry, apple, Banana, the result is Apple, apple, banana, Banana, cherry. Lines that tie after ignoring case keep their original relative order, which is why Apple stays ahead of apple and banana ahead of Banana.
If you untick the case option, the sort follows your browser's language rules, where a lowercase letter sorts just before its capital: apple, Apple, banana, Banana, cherry. It does not behave like old computer sorts where every capital letter came before every lowercase letter, so Zoe does not jump ahead of adam.
Accents and non-English letters
The alphabet and natural modes use locale-aware comparison. Accented letters sort beside their base letters instead of at the end of the list. For example, Zoe, Émile, adam, Eve and öland come out as adam, Émile, Eve, öland, Zoe. Languages with their own order for particular letters may be sorted using the browser's default rules, which are not always identical to a dictionary in that language, so check any list where the exact order matters.
Sorting by the number at the start of a line
The tool reads the number at the beginning of each line, so 12 apples comes after 3 eggs. Commas in the number are understood, and 1,200 grams flour is read as 1200. Decimals and negative numbers work too. For the lines 3 eggs, 12 apples, 1,200 grams flour, salt, -4 degrees and 0.5 cup, the ascending order is -4 degrees, 0.5 cup, 3 eggs, 12 apples, 1,200 grams flour and then salt.
A line with no number at its start, such as salt, goes to the end in its original position among the other such lines. A currency symbol at the start is not a number, so $5 is treated as having none. Strip the symbol first if you want those lines ordered by amount.
Spaces, blank lines and sorting by length
Leading spaces count as characters. In the list " beta", "alpha", " gamma", an empty line and "delta", the indented lines and the empty line all come first. With trimming and removal of empty lines turned on, the result is alpha, beta, delta, gamma. If a sorted list looks wrong, stray spaces at the start of some lines are the usual cause.
Length mode counts characters, so aaa, b, cc and ddd sort from short to long as b, cc, aaa, ddd, and with descending ticked as aaa, ddd, cc, b. Lines of equal length keep their original order. Reverse mode just flips the list, which is useful when a list was already sorted the wrong way or is in date order. Shuffle gives a new random order each time you press the button.
Questions
Is the sort case sensitive?
By default it ignores case. Untick that option to treat capitals separately.
Does it sort Bangla?
Yes, using your browser's language rules.
How is a tie handled?
Lines that compare equal keep their original order.
Is anything uploaded?
No. Your text stays in your browser and is never sent anywhere.
Does sorting remove duplicate lines?
No. Every line is kept, so repeated lines end up next to each other. Remove them afterward with a duplicate line remover if you want a list of unique entries.
Why is my list not sorted the way I expect?
The most common causes are leading spaces, mixed upper and lower case with the case option off, or numbers inside the text. Try trimming the lines, turn on ignoring case, or switch from alphabet to natural order.
Can I sort a CSV file by one column?
Not directly. The tool sorts whole lines, from the first character. To sort by another column, paste that column on its own, or move the sort key to the start of each line first.
Is the shuffle truly random?
Each press reorders the lines with a standard fair shuffle, so every order is equally likely. It is fine for picking a speaking order or a draw, but do not use it where a result must be verifiable, since there is no record of the shuffle.
Do blank lines stay in the result?
Yes, unless you tick Remove empty lines. Blank lines count as empty text and sort to the top in alphabetical order, or to the end in number mode.