What This Tool Does

This tool sorts lines of text using one of several methods: alphabetical (A–Z or Z–A), numeric (for lists of numbers), by line length, or reverse the original order. Options include case-sensitive sorting, removing duplicates, and locale-aware comparison for accented characters.

Inputs Explained

How It Works

The text is split by newlines into an array. The chosen sort method is applied using JavaScript's Array.sort with a custom comparator. Alphabetical uses localeCompare for proper handling of accents and Unicode. Numeric sort parses each line as a number. Length sort compares string lengths.

Formula / Logic Used

A-Z: a.localeCompare(b) Numeric: parseFloat(a) - parseFloat(b) Length: a.length - b.length Reverse: array.reverse()

Sort Lines Alphabetically

Sort any list of lines alphabetically, numerically, by length, or reverse order.

Step-by-Step Example

Input:

banana
Apple
cherry
10
2
apple

Method: Alphabetical A-Z (case insensitive)

Output:

10
2
Apple
apple
banana
cherry

For numeric sort: 2, 10, Apple, apple, banana, cherry (numbers first in ascending order, text alphabetically after).

Use Cases

Assumptions and Limitations

Disclaimer: All sorting happens in your browser. Your text is never uploaded or logged.

Frequently Asked Questions

How does the alphabetical sort handle uppercase vs lowercase?

By default, the sort is case-insensitive — 'Apple' and 'apple' are grouped together. Enable 'Case sensitive sort' to put uppercase letters before lowercase in the output.

Why are my numbers sorting as '1, 10, 2, 20'?

That's alphabetical order. Use 'Numeric' sort to get the correct 1, 2, 10, 20 order. Alphabetical sort compares character by character — '1' comes before '2' but '10' comes between '1' and '2' because it starts with '1'.

What happens to empty lines?

By default, empty lines are removed before sorting. Uncheck 'Remove empty lines' to keep them — they'll sort to the top of alphabetical order since empty strings sort first.

Is the sort stable?

Yes. Modern JavaScript engines guarantee stable sort — when two lines compare equal, their relative input order is preserved. This matters when sorting by one key but wanting to retain another implicit order.

How does Unicode sorting work?

Case-insensitive sort uses localeCompare, which is Unicode-aware and handles accented characters (é sorts near e). Case-sensitive sort uses raw codepoint comparison, which may order accented characters differently.

Can I sort by something other than the whole line?

This tool sorts whole lines. For column-based sorting (like sorting CSV by a specific column), use a spreadsheet tool like Excel or Google Sheets.

How random is the shuffle?

It uses the Fisher-Yates shuffle with Math.random, which is unbiased and suitable for most casual use. For cryptographically random shuffles (e.g., lottery), use a tool built on crypto.getRandomValues.

Is my data saved?

No. All sorting runs entirely in your browser. Text never leaves your device and is not logged anywhere.

Sources and References

Related Calculators

Remove Duplicate LinesFind & ReplaceReverse TextWhitespace RemoverCase ConverterWord Counter