Sort Lines
Sort lines alphabetically, numerically, by length or at random.
Sorting happens in this page. Your lines are never uploaded.
Putting a list in order is the kind of task that is instant in a spreadsheet and annoying everywhere else — in a text file, in a config block, in a message you are about to send.
More about Sort Lines
Alphabetical order here goes through the browser’s collator in the language of the page, not through a plain string comparison. That distinction is not academic. Comparing strings by code point puts every accented character after `z`, so a Vietnamese name list sorted that way has Ánh, Đức and Yến in an order no Vietnamese reader would accept. Reading this page in Vietnamese gets the Vietnamese alphabet; reading it in English gets the English one.
Natural order is on by default, which is what puts `item2` before `item10`. Strict alphabetical order puts `item10` first, because `1` comes before `2` character by character — correct, and almost never what anybody wanted.
There is also numeric sorting by a leading number, sorting by line length, and a random shuffle. The shuffle uses the same cryptographic randomness the rest of this site uses rather than `Math.random`, with rejection sampling so that no position is very slightly more likely than another.
- Alphabetical order in the language of the page, not by code point
- Natural order so item2 comes before item10
- Numeric sorting by a number at the start of the line
- Sorting by line length, counted in characters a reader would count
- Unbiased random shuffle using cryptographic randomness
- Optional case sensitivity, reversal and blank-line removal
How to use it
- 1Paste your lines into the input.
- 2Choose what to sort by, and reverse it if you want descending order.
- 3Turn natural order off if you want strict alphabetical instead.
- 4Copy or download the sorted result.
Questions
Does it sort Vietnamese correctly?
Yes, when you are reading the Vietnamese version of the page it uses the Vietnamese alphabet. Sorting by code point would put every accented letter after z.
What is natural order?
It reads runs of digits as numbers, so item2 comes before item10. Strict alphabetical order puts item10 first because 1 precedes 2.
What happens to lines with no number in numeric mode?
They keep their original order and go to the end, rather than being scattered through the list.
Is the shuffle really random?
It uses the browser’s cryptographic randomness with rejection sampling, so every arrangement is equally likely. Math.random is not used anywhere here.
Are duplicate lines removed?
No, sorting keeps every line. Use the duplicate remover first if you want a list that is both unique and sorted.