Skip to content
AgileLogics

Text Sorter

Sorts each line of a block of text alphabetically (A-Z or Z-A), numerically, or shuffles them into a random order.

How it works

Paste your text, choose a sort order, and click Convert.

What is a text sorter?

A text sorter puts the lines of a block of text in order. Paste a list with one item per line, such as names, keywords, file names or numbers, and the tool sorts it alphabetically from A to Z or Z to A, numerically in either direction, or shuffles it into a random order. Each line moves as a whole and its text isn't changed.

How to sort lines

  1. Paste the lines you want to sort into the input box.
  2. Pick a Sort Order: Alphabetical (A-Z), Alphabetical (Z-A), Numeric (ascending), Numeric (descending) or Random.
  3. Click Convert and copy the sorted list.

Worked example: alphabetical

Input:

banana
Apple
cherry
apple
Éclair
eclair
item10
item2
Zebra

Alphabetical (A-Z) output:

Apple
apple
banana
cherry
Éclair
eclair
item10
item2
Zebra

Three things are going on here. Apple and apple count as the same word, so they stay in the order they were pasted. Éclair sorts with the e's rather than after Zebra, because accents are ignored too. And item10 lands before item2, because the comparison is character by character and "1" comes before "2".

Z-A mode sorts in the opposite direction, starting with Zebra, but lines that compare equal still keep their pasted order: Apple then apple, and Éclair then eclair.

How alphabetical order is decided

The tool compares lines with JavaScript's localeCompare() at "base" sensitivity, using your browser's language settings. Base sensitivity means only the underlying letter counts: case and accents are ignored.

Using the browser's language matters for some alphabets, because sort order is a rule of each language, set out in the Unicode Collation Algorithm and its per-language tailorings:

Line English or German browser Swedish browser
ä sorts with a sorts after z
Ø sorts with o sorts after z (also in Danish and Norwegian)

So two people sorting the same list can get slightly different results if their browsers are set to different languages. Both are correct for their language.

Worked example: numeric

Numeric mode reads the number at the start of each line. Leading spaces, one currency symbol (such as $, € or £) and comma thousands separators are skipped, so prices and large figures sort by their value. Here's a messy list sorted with Numeric (ascending):

Line Value used for sorting
-$5 -5 (sign before the currency symbol)
-3 -3
abc 0 (doesn't start with a number)
0.25 0.25
7 7
9.5 9.5
10 10
$20 20 (currency symbol skipped)
100 kg 100 (unit ignored)
€ 1,200.50 1200.5
1,500 1500 (thousands separator skipped)
2e3 2000 (scientific notation)

The output is in exactly that order, and Numeric (descending) gives the reverse. In alphabetical mode the same list would put 10 and 100 kg before 2e3 and 7, since it compares characters, not values.

A comma only counts as a thousands separator when exactly three digits follow it, so 1,500,000 is 1500000 but 1,5 (a European decimal comma) is read as 1. Change decimal commas to points first with find and replace if your list uses them. Lines with equal values keep their original order in both directions.

Random order

Random mode shuffles the lines with the Fisher-Yates algorithm, so every possible order is equally likely, and clicking Convert again gives a new shuffle. It uses Math.random(), which is fine for shuffling a playlist or a list of quiz questions but isn't meant for draws where fairness has to be provable.

Tips

  • Remove duplicates after sorting. Sorting keeps every line. Remove Duplicate Lines keeps the first copy of each, and the result stays sorted.
  • Fix capitalization separately. The sort ignores case but doesn't change it. Use the case converter if you want the list in one consistent case.
  • Watch for hidden spaces. A leading space is a character like any other, so zebra (with a space) sorts before apple alphabetically.
  • Comparing two lists? Sort both the same way, then compare them in the code diff tool to see what's missing from each.

Everything runs in your browser, so lists with names or email addresses aren't uploaded anywhere.

Last updated

Frequently asked questions

Is the alphabetical sort case-sensitive?
No. Apple, apple and APPLE are treated as equal, and so are letters with and without accents, such as Éclair and eclair. Lines that compare equal keep the order they had in your input.
Why does item10 come before item2?
The alphabetical modes compare text character by character, and the character 1 sorts before 2. The numeric modes don't help here either, because they only read a number at the very start of a line. Pad the numbers with zeros (item02, item10) to get the order you expect.
How does the numeric sort read each line?
It reads the number at the start of the line, ignoring leading spaces, a currency symbol and thousands separators, so 1,500 counts as 1500, $20 as 20, 100 kg as 100 and 2e3 as 2000. Anything after the number is ignored. Lines that don't start with a number, such as abc, count as 0.
What happens to blank lines?
Empty lines at the very start and end of your text are dropped, which stops a trailing line break from adding a blank line to the result. Blank lines in the middle are kept and sorted like any other line, so they move to the top in A-Z order.
Does sorting remove duplicate lines?
No. Every line is kept, so duplicates end up next to each other. Run the result through Remove Duplicate Lines if you want each line only once.