Sort Lines Alphabetically

Alphabetical sorting with proper natural ordering, plus sort by length, reverse, shuffle, line numbering and bulk prefix/suffix.

Natural sorting, not ASCII sorting

A plain alphabetical sort puts item10 before item2, because it compares character by character and 1 sorts before 2. That is correct by the letter of the algorithm and wrong by every human expectation.

This tool sorts naturally: runs of digits are compared as numbers, so you get item2, item10, item20 in the order you would write them yourself. Sorting is also case-insensitive and accent-aware, using your browser's locale rules — so in a list of Italian names Ácari lands next to Acari rather than being exiled to the end of the list, which is what a raw byte comparison would do.

The other five modes

Sort by length is an underrated diagnostic. Sorting shortest first surfaces the empty and near-empty rows that indicate a broken export; sorting longest first brings the runaway rows — the ones with an unescaped delimiter that swallowed the rest of the file — straight to the top.

Reverse flips the existing order without sorting, which is the right tool for chronological logs where the order is already meaningful and you simply want the newest entries first.

Shuffle randomises the order using a Fisher–Yates shuffle, so every arrangement is equally likely. Useful for picking a random winner, randomising question order, or creating an unbiased sample from a list.

Number lines prefixes each line with a counter, starting from whichever number you choose. Add prefix/suffix wraps every line in the strings you supply — the fastest way to turn a bare column into quoted, comma-separated values ready to paste into code.

Combining tools: deduplicate first, then sort. Doing it in the other order works too, but deduplicating a sorted list and then sorting again is one step more than you need.

A note on trailing newlines

If your text ends with a newline, that final empty line is preserved at the bottom rather than being sorted up to the top as an empty string. It is a small detail, but it stops a sorted file from acquiring a stray blank first line every time you run it.

Frequently asked questions

Does it sort numbers correctly?

Yes. Sorting is natural, so item2 comes before item10 rather than after it. Digit runs inside a line are compared numerically instead of character by character.

Is the sort case-sensitive?

No. Apple and apple sort next to each other rather than in separate blocks, which matches how people expect a list to be ordered. Accented characters are also sorted according to your browser's locale rules.

How random is the shuffle?

It uses a Fisher–Yates shuffle, which gives every possible ordering an equal probability. It is suitable for picking winners or randomising a sample, though not for cryptographic purposes.

Can I quote every line for pasting into code?

Yes — use Add prefix/suffix with a prefix of " and a suffix of ",. For proper JSON, the list-to-JSON-array tool handles escaping as well.