Text Sorter
Sort lines of text alphabetically, by length, or numerically — ascending or descending.
Did this tool work for you?
How to use this calculator
- 1
Enter one item per line in the text box.
- 2
Choose a sort order and whether to remove duplicates.
- 3
The sorted list appears instantly below.
Frequently asked questions
Why does "item10" come before "item2" in A → Z?
The sort compares text, not numbers, so it looks at the characters one by one: "item1" is followed by "0" in "item10" and by nothing in "item1", and "item10" then beats "item2" because "1" comes before "2". The result for item10, item2, item1 is item1, item10, item2. The tool has no natural-sort mode. If every line is a plain number, use the numeric orders instead; for mixed names like file10.txt you would need to pad the numbers (file02, file10) before sorting.
How does the numeric sort treat lines that are not plain numbers?
It reads the number at the start of each line with parseFloat. "10 apples" counts as 10 and "1e3" counts as 1000, but "1,000" counts as 1 because the parser stops at the comma, and "$5" has no number at all. Lines with no leading number are placed after the numeric ones in both ascending and descending order, sorted alphabetically among themselves. Strip currency symbols and thousands separators first if you want those lines ranked by value.
What does "remove duplicates" compare, and which copy survives?
Removal runs before sorting and compares whole lines exactly. In the case-sensitive mode "apple", "Apple" and "apple " (with a trailing space) are three different lines; in the case-insensitive mode "apple" and "Apple" merge but "apple " still stays separate, because lines are never trimmed. When two lines merge, the first one in your original order is kept, so "banana" followed later by "Banana" leaves "banana".
How are accented letters and capitals ordered?
A → Z and Z → A use the browser’s locale-aware comparison rather than raw character codes, so "ä" and "á" sit next to "a" instead of after "z". With an English locale, a lowercase word comes just before its capitalised twin: the sample ant, änt, Apple, ápple, zebra, Zebra came out in exactly that order. Other locales or browsers can order a few characters differently, because the rules come from the browser, not from this tool.
Are blank lines kept?
Yes. A blank line is a line with no characters, so it is counted in the Line Count and, in A → Z order, sorts to the top. A trailing newline at the end of your paste therefore turns into one blank entry. If you do not want them, delete the empty lines before sorting. With duplicate removal switched on, several blank lines collapse to one.
Does shortest/longest first count characters or bytes?
It uses the length of each line as JavaScript measures it, in UTF-16 units. Plain letters count as 1 each, but an emoji counts as 2. Lines of equal length are ordered alphabetically, so "kiwi", "pear" and "plum" appear in that order when they tie at four characters.
Is the random shuffle suitable for a prize draw?
Not for anything that needs to be auditable or tamper-proof. The shuffle is a standard Fisher-Yates pass driven by the browser’s Math.random, which is fine for ordering a speaking rota or randomising quiz questions but is not a cryptographically secure source. Each press of the button gives a different order, and the tool cannot reproduce an earlier one.
Can it sort a comma-separated list or a table column?
No. Only whole lines are sorted, so a comma-separated list is treated as one line. Put one item per line first, for example by replacing the commas with line breaks in a text editor. The tool also cannot sort by a field inside each line, such as the second column of a CSV.
Sorting lines of text: order, duplicates and numbers
What each sort order does
Every order works on whole lines, one item per line. The table shows the six deterministic orders applied to the same six lines: pear, Fig, 10, apple, 9 and "banana split". Notice that A → Z puts 10 before 9, because text sorting compares characters rather than values, while the numeric orders rank 9 and 10 by value and leave the three words at the end in alphabetical order.
| Order | Result |
|---|---|
| A → Z | 10, 9, apple, banana split, Fig, pear |
| Z → A | pear, Fig, banana split, apple, 9, 10 |
| Shortest first | 9, 10, Fig, pear, apple, banana split |
| Longest first | banana split, apple, pear, Fig, 10, 9 |
| Numerically, smallest first | 9, 10, apple, banana split, Fig, pear |
| Numerically, largest first | 10, 9, apple, banana split, Fig, pear |
Worked example: de-duplicating a mailing list
Take the lines banana, Apple, cherry, apple, Banana and date, then choose A → Z with case-insensitive duplicate removal. The output is Apple, banana, cherry, date, and the line count drops from 6 to 4. The kept spellings are the first ones encountered, so the capital A of "Apple" survives and the lowercase "apple" that followed it is dropped. Switching to case-sensitive removal would have kept all six lines, because none of them match exactly.
Worked example: numbers mixed with text
The lines 10, 2, 1.5, n/a, -3 and 100 sorted numerically from smallest give -3, 1.5, 2, 10, 100 and then n/a. The negative number and the decimal are read correctly, and the one line that is not a number drops to the end. Sorted alphabetically instead, the same list would start with -3 and put 10 before 2, which is rarely what you want for figures.
Length-based orders and ties
Sorting by length is handy for spotting the longest entries in a list of titles, meta descriptions or file names. For pear, fig, banana, kiwi and plum, shortest first returns fig, kiwi, pear, plum, banana: the three four-letter words keep alphabetical order among themselves. Spaces and punctuation count as characters, so "banana split" is far longer than "banana".
What the tool leaves alone
Lines are never trimmed, merged or edited, only reordered and optionally de-duplicated, so stray spaces at the end of a line will make otherwise identical entries look different. Windows and Unix line endings are both recognised. For anything more elaborate, such as natural ordering of file numbers, sorting by a column or sorting while ignoring a leading "The", clean the lines up before pasting them in.
Learn more from an authoritative source:
WikipediaFind & Replace
Find and replace text within any content — with plain text or regex support.
Remove Extra Spaces
Remove extra spaces, tabs, and blank lines from text — clean and reformat in one click.
Text Repeater
Repeat any text or phrase a set number of times with a custom separator.
Lorem Ipsum Generator
Generate placeholder Lorem Ipsum text by words, sentences, or paragraphs.
Text Cleaner
Remove special characters, HTML tags, punctuation, numbers, or any custom characters from text.
Readability Score Calculator
Calculate the Flesch Reading Ease score, Flesch-Kincaid grade level, and key text statistics for any piece of writing.
Results are estimates for informational purposes only and do not constitute professional financial, medical, legal, or technical advice. Read full disclaimer →