ToolForge
Advertisement

Text Sorter

Alphabetize, natural-sort, or sort by number, date or column

Written by toolforge.websiteLast reviewed How we build and check these tools

Text Sorter tool

0 lines in · already in this order

Your list
0 lines in · already in this order

Order by

Dictionary order for the language you choose below.

Prefixes each line with its new position and a tab.

Strips leading and trailing whitespace from the text written out, not just the comparison.

How lines are compared

Off, Apple and apple sort together. On, capitals are ordered apart.

Without this an indented line sorts by its indent rather than its text.

Shelves titles the way a library does: The Matrix files under M.

A leading bullet, quote or bracket stops deciding the order.

Files élan next to elan. Wrong for languages that alphabetise accents separately.

Languages disagree: Swedish files ä after z, German files it next to a. Pick one explicitly if the result has to match somewhere else.

Matters under length, word-count, number and date sorting, where many lines share a value.

List structure

Set this to 1 to keep a CSV header row above the sorted data instead of alphabetising it into the middle of the list.

Blank lines
How the list is separated

Line mode reads all three line endings and writes back the one your text arrived with, so a file saved on Windows stays a Windows file.

Ready-made settings (9)
Result0 lines

Text Sorter: key facts

What it does
Alphabetize, natural-sort, or sort by number, date or column
Category
Text Tools
Cost
Free, with no account, sign-up, or install.
Your data
Runs entirely in your browser — the files and text you enter are never uploaded to a server.
Last reviewed
. Report an incorrect result.
Advertisement

About the Text Sorter

Getting a list into order is trivial for a computer and tedious by hand, but the version of it most tools ship has two problems: it overwrites your list, and it only knows one kind of order. This Text Sorter writes its result into a separate box, so the arrangement you started with is still there when the ordering turns out not to be the one you wanted, and an undo button covers everything else.

Nine orderings cover the jobs people actually bring to a sorter. Alphabetical, in an alphabet you pick rather than whichever one the browser happened to default to. Natural, which reads the digits inside a string as numbers, so item2 lands before item10 the way a file manager would put it. By the number in each line, for a price list or a scoreboard. By the date in each line. By character count or by word count. A shuffle, and a plain reverse that flips the current order without sorting anything.

What gets compared is separate from what gets moved. Indentation, capitals, punctuation, accents and a leading "The" can each be excluded from the comparison without being removed from your text — so an indented outline sorts by its words rather than by its indent, and a film list files The Matrix under M while still reading "The Matrix" in the result. You can also narrow the comparison instead of loosening it: sort a CSV by column three and the entire row travels with it, or sort by a regular-expression match to order lines by a trailing number or a surname.

Two things stay put while everything else moves. A header row can be held at the top rather than alphabetized into the middle of the data, and blank lines can keep their positions so a spaced list survives with its spacing intact. Lists separated by commas, semicolons or tabs work as well as one item per line, and the result can come back separated however the next step needs it.

Sorting structured text without breaking it

Reordering lines destroys any meaning that depended on their sequence, which makes a naive sort actively dangerous on a CSV, a configuration file or anything with a header. Three controls exist for that. Holding the first line or two at the top keeps a header row above the data instead of alphabetizing it into the body. Leaving blank lines where they are keeps a spaced list's structure, with the entries sorting around the gaps rather than the gaps being deleted. And comparing one column rather than the whole line means a row sorts by the field you care about while staying intact.

The column comparison is a plain separator split, not a full CSV parse: a quoted field that itself contains the separator will be split at it. For well-formed exports without embedded separators it is exact; for anything more involved, the pattern mode gives you a regular expression instead, using its first capture group as the sort key when it has one.

Both narrowing modes have to say what happens to a line that has no key — a row with fewer columns than you asked for, or a line the pattern does not match. Those lines are kept and collected at the end, never quietly interleaved into a position the comparison cannot justify, and the count is reported beneath the controls.

How to use it

  1. Paste the list you want reordered into the box at the top, or drag a .txt or .csv file over it.
  2. Choose an ordering — alphabetical, natural, by number, by date, by length, by word count, shuffle or reverse — and a direction.
  3. Set what gets compared: ignore capitals, indentation, punctuation, accents or a leading article, or compare only one column or one pattern.
  4. Hold a header row on top if you have one, and decide whether blank lines are removed, kept in place, or sorted.
  5. Copy or download the result, or press "Use as input" to sort it again.

Why item10 came before item9

Comparing text proceeds character by character, and "1" comes before "9", so as far as a plain alphabetical comparison is concerned item10 precedes item9 and 100 precedes 2. This is not a bug in the comparison; it is the correct answer to a question about text being asked about numbers. Zero-padding to a fixed width is the traditional workaround, which is why files meant to sort correctly are numbered 001, 002, 003.

Natural ordering asks the right question instead. It walks the string looking for runs of digits and compares those runs as values while comparing everything around them as text, so item2, item9, item10 and item100 land in the order a person would put them. It is what a file manager uses and what a version list needs, and it is one click away here rather than an argument for renaming everything.

Ordering by the number is different again, and worth reaching for when the text around the number is noise. It finds the first number anywhere in the line — through a currency symbol, a thousands separator or a minus sign — and orders on that value alone, so a price list sorts by price no matter how each line is worded. Lines with no number in them are gathered at the end rather than treated as zero, because a missing value is not a small one.

  • Alphabetical puts item100 second; natural puts it last.
  • Ordering by number reads $1,299.00 as 1299 and sorts it after $89.
  • A line with no number in it is left at the end, with a note saying how many were.

Why use this version

  • The result appears in its own box, so sorting never destroys the order you started with, and an undo covers every change you do commit.
  • Natural ordering fixes the item10-before-item9 problem without renaming anything, and ordering by number or date handles the cases text comparison cannot.
  • The alphabet is an explicit choice rather than a browser default, so a result can be reproduced and matched against another system.
  • Indentation, capitals, punctuation, accents and leading articles can be excluded from the comparison without being removed from your text.
  • A header row can be held on top and blank lines can keep their positions, so structured text survives being sorted.
  • The shuffle is seeded: note the seed and anyone can reproduce the same draw, which a Math.random shuffle can never offer.
  • Everything runs in your browser. Nothing is uploaded, and line endings survive the round trip.

There is no single correct alphabetical order

Languages disagree about their own alphabets, and the disagreement is not a rounding error. Swedish files å, ä and ö after z, as distinct letters at the end of the alphabet. German treats the same characters as variants of a and o and files them next to their base letters. Traditional Spanish once sorted ch as a single letter between c and d. Each of those is correct in its own language and wrong in the others.

A tool that says nothing about which alphabet it is using produces a result that differs between visitors and cannot be reproduced. So the alphabet is an explicit choice here, defaulting to your browser's language and offering a list of others — plus raw character-code order, which is what the Unix sort command and most programming languages do, and which is the right answer when the output has to match something a machine produced.

Capitals interact with this. Character-code order puts every capital letter before every lowercase one, so a mixed-case list comes back in two blocks rather than one sequence — the behaviour that surprises people most. Matching case is therefore off by default; turn it on when you want the two blocks.

Frequently Asked Questions

How do I stop item10 sorting before item9?

Choose the Natural ordering instead of Alphabetical. It reads runs of digits inside each line as numbers rather than as text, so item2, item9, item10 and item100 come back in that order. If the text around the number is irrelevant, "By number" orders on the first number in each line alone.

Can I sort a CSV by one of its columns?

Yes. Under "How lines are compared", set Sort by to "One column of each line", give it the separator and the column number, and the whole row moves according to that field. Set "Lines to hold at the top" to 1 to keep the header row above the sorted data. Note this is a plain separator split, not a full CSV parse, so a quoted field containing the separator will be split at it.

What is the difference between Reverse and a descending sort?

A descending sort orders the lines by the chosen key and then flips that ordering, so the result is sorted. Reverse does not sort at all — it flips the order the lines are already in. If your list is in a custom sequence, Reverse mirrors it while a descending alphabetical sort would discard it.

Is the shuffle random, and can I repeat one?

It is an unbiased Fisher–Yates shuffle, so every arrangement is equally likely, but it is driven by a seed rather than by Math.random. That means the same list with the same seed always produces the same order, so a draw can be repeated and checked by someone else. "Shuffle again" moves to the next seed.

Why did my indented lines all sort to the top?

They will not here — "Ignore surrounding whitespace" is on by default, so an indented line is compared by its text rather than by its indent. Turn that option off if you actually want indentation to decide the order. The indentation itself is never removed from the result either way.

Which dates can it read?

ISO dates such as 2024-03-04, written months such as 4 March 2024 and March 4, 2024, and numeric slash, dot or dash dates. Because 3/4/2024 means two different days in different countries, there is no guessing: you tell it whether to read day first or month first, and the choice is echoed back. Anything it cannot read unambiguously is left at the end and counted rather than sorted into a position it cannot justify.

Does it remove duplicates too?

No, and deliberately. Deduplication is a bigger question than a checkbox can answer — which copy survives, and what counts as the same — so it lives in the Duplicate Line Remover, which offers five behaviours and a report of exactly what repeated. Sort here, then send the result there, or the other way round.

Related Tools

Advertisement
Buy Me a Coffee