Sort lines of text: alphabetical, by length, numeric, deduplicated
Paste your lines, pick a mode — alphabetical, by length, or by the number inside each line — then optionally reverse, shuffle, or deduplicate, and press Sort. Everything runs in the browser; the text is never uploaded.
When sorting actually helps
The everyday case is tidying a flat list: keywords, domains, names, tags. One item per line, sorted before it goes into a spreadsheet or a document, is faster than clicking around in a table.
The second case is making numbered names read the way people expect. Logs and filenames often contain file2 and file10; a plain character comparison puts file10 first, while numeric comparison matches intuition.
After merging several lists you usually want duplicates gone and the result ordered by length. Short words first works well for tag lists, word clouds, and dropdown options.
- Tidy a keyword or domain list alphabetically
- Merge several lists, deduplicate, then sort by length
- Order filenames or IDs by the number inside them
- A quick shuffle where order carries no meaning
How to avoid the usual mistakes
Start by making sure the input is one item per line. The tool compares whole lines and does not parse commas or tabs, so sorting one column of a CSV means splitting the columns first or using a spreadsheet. Blank lines are dropped, not kept as spacers.
Alphabetical mode uses natural ordering for runs of digits, so file2 sorts before file10. If you want strict character order this will look wrong; zero-pad the numbers to file02 and file10 and both orders agree.
Deduplication is exact: it is case-sensitive and does not trim whitespace. Apple and apple both survive and simply end up next to each other, and a leading space makes a third distinct line. For case-insensitive deduplication, clean the list with the text dedupe tool first.
Shuffle uses Math.random, which is fine for a quick mix but not for a raffle or team assignment: there is no verifiable randomness and no way to reproduce the result.
Chinese ordering is delegated to the browser's localeCompare('zh-Hans-CN'), not computed here. Chrome, Safari, and Firefox each ship their own collation data, so Han characters come out roughly in pinyin order but can differ for polyphonic characters, rare characters, and browser versions. For a name roster or glossary that must be stable, do not rely on the browser.
- One item per line; commas are not split into columns
- Blank lines are dropped
- Deduplication is exact; normalise case and spaces first
- Strict pinyin or stroke order needs another tool
Alternatives and limits
Command-line sort is more predictable: LC_ALL=C sort compares bytes and gives the same result everywhere, sort -t, -k2 sorts one CSV column, sort -u deduplicates, and sort -R shuffles. It also handles files far larger than a text box.
A spreadsheet is the better home for structured data: column sorting, deduplication, and filtering all keep the other columns intact. The cost is importing the data first.
This tool only handles whole lines. It cannot sort by a column, cannot produce strict pinyin or stroke order, and its shuffle is not suitable for anything that needs fairness. Past a few megabytes the page slows down because every line stays in memory.
- Fixed order or column sort → sort or a spreadsheet
- Strict pinyin or stroke order → a dictionary-based tool
- Raffle or team assignment → verifiable randomness
FAQ
Does it sort Chinese by pinyin?
Roughly, but not guaranteed. Comparison is delegated to the browser's localeCompare('zh-Hans-CN'), and Chrome, Safari, and Firefox each rely on their own collation data. Han characters come out close to pinyin order, but polyphonic characters, rare characters, and browser versions can change the result. For a fixed order, use LC_ALL=C sort to compare bytes, or compare Unicode code points in a script.
Why does file2 come before file10?
Alphabetical mode compares runs of digits numerically, so file2 is smaller than file10. A plain character comparison would give the opposite result, because the character 1 is less than 2. Zero-pad the numbers to file02 and file10 if you want both interpretations to agree.
I enabled dedupe, so why are Apple and apple both still there?
Deduplication uses exact Set comparison: it is case-sensitive and does not trim leading or trailing spaces, while the sort comparison ignores case. Both lines survive and are simply displayed next to each other. A line with a leading space counts as a separate entry. For case-insensitive deduplication, run the list through the text dedupe tool first.
Related tool:Sort Lines