Sort Text Lines
Sort lines alphabetically, numerically, by length, in reverse or shuffled, with options to trim, drop blanks, remove duplicates and ignore case.
Alphabetical sorting is locale-aware and natural: “item2” comes before “item10”. Number mode reads the leading number on each line and ignores the rest, so “3. Apples” sorts by 3. Length ties fall back to alphabetical order. Everything runs in your browser.
Sorting lines: alphabetical, natural, numeric
Sorting a list of lines is one of those tasks that is trivial until the details bite. Plain ASCII sorting puts "Item10" before "Item2" because it compares character by character and "1" comes before "2". This tool uses natural, locale-aware comparison by default, so numbers embedded in text sort the way a human expects.
The modes cover the common needs. A→Z and Z→A are lexical. Number mode ignores everything except the first number on each line — handy for lists like "3. Apples" or "12) Oranges" where the label, not the text, is the key. Length mode is useful for finding the longest or shortest entries, with ties broken alphabetically. Reverse simply flips the current order, and Shuffle randomises it with a Fisher–Yates pass.
The cleanup options run before the sort. Trimming each line removes stray leading and trailing spaces that would otherwise affect both comparison and appearance. Dropping blank lines removes the gaps that accumulate when you paste from a document. Removing duplicates keeps only the first occurrence of each line. Case-insensitive comparison groups "Apple" and "apple" together instead of separating all capitals from all lowercase.
Typical uses: alphabetising a glossary or bibliography, ordering CSV rows by a leading ID, tidying an import list, de-duplicating and sorting a keyword list, or generating a random running order for a playlist or a set of tasks. For heavy deduplication work, the dedicated Remove Duplicate Lines tool gives you more control over which copy to keep.
Everything happens in your browser — nothing is uploaded, and the tool works offline once loaded.
Worked example: natural vs plain sorting
Input: A→Z (natural): Number mode: file10.txt file1.txt 1) Pears file2.txt file2.txt 2) Apples file1.txt file10.txt 10) Plums A plain character-by-character sort would give file1, file10, file2.
Natural ordering compares the digits inside text as numbers, which is what people expect for file names, versions and chapter lists. Number mode ignores the text and sorts only by the leading number.
Choosing the right mode
- A→Z / Z→A: names, glossaries, tags. Accented letters sort with their base letter (é next to e).
- Number: ranked lists, numbered steps, rows that start with an ID.
- Length: spotting unusually short or long entries, such as truncated values in an import.
- Reverse: flips the current order without sorting — handy for log files that list oldest first.
- Shuffle: random order for quizzes or running orders. It uses Math.random, which is fine for that but not for drawing prizes — use the random number generator for fair draws.
- Remove duplicates while sorting: tick the option to keep only the first occurrence of each line before the list is ordered — useful for tag and keyword lists.
Why other tools sort differently
Spreadsheets and many programming languages sort text character by character by default, which is why “file10” lands before “file2” in Excel, and why uppercase letters sort before all lowercase ones in a plain ASCII sort. This tool uses natural, locale-aware comparison instead (in JavaScript terms, localeCompare with numeric collation). On the command line, GNU sort -V (“version sort”) gives similar results for names with numbers; sort -f ignores case.
Related tools
These free tools pair well with this page — open them in a new tab to finish your workflow.
Frequently Asked Questions
How does alphabetical sorting handle numbers in the text?
The A→Z and Z→A modes use natural, locale-aware ordering, so "item2" sorts before "item10" rather than after it. If you want to sort purely by a leading number and ignore the rest of the line, use the Number modes instead.
What does Number mode sort on?
It reads the first number it finds at the start of each line — integer or decimal, with an optional minus sign — and orders by that value. "3. Bananas" and "3) Bananas" both sort as 3. Lines with no leading number are treated as 0.
Is the sort case-sensitive?
By default it is case-insensitive, so "apple" and "Apple" sort together. Untick "case-insensitive" to get ASCII-style ordering where uppercase letters come before lowercase.
What do "trim" and "drop blank lines" do?
"Trim each line" removes leading and trailing spaces before sorting and from the output. "Drop blank lines" removes empty lines entirely. Both are on by default because they usually give a cleaner result for pasted lists.
Can it remove duplicates at the same time?
Yes. Tick "remove duplicates" and only the first occurrence of each line is kept, then the sort is applied. For a dedicated deduplication tool with more control, use Remove Duplicate Lines.
Does Shuffle give a truly random order?
It uses a Fisher–Yates shuffle seeded by the browser's Math.random, which is fine for reordering a list, picking a random running order, or breaking alphabetical bias. It is not cryptographically random — do not use it for anything security-sensitive.
Is my text uploaded?
No. All sorting happens in your browser and nothing is sent to a server. The tool works offline once the page has loaded.