Multi-line Text Sorter

Sort lines alphabetically, numerically, by length, or reverse

Sort any list of lines instantly: alphabetical A-Z or Z-A, numeric low-to-high or high-to-low, by line length, or just reverse the order. Optional case-insensitive matching and whitespace trimming. Runs in your browser. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

How does numeric sorting handle non-number lines?

Each line is parsed from its start as a number. Lines that do not begin with a number are treated as non-numeric and pushed to the bottom of the list in both ascending and descending modes, so your numbers stay cleanly ordered.

Sorting a list by hand is tedious and error-prone. This tool splits your input on line breaks and reorders it instantly using whichever rule you pick, with optional case folding and whitespace trimming so messy pasted lists come out clean.

How it works

The input is split on newlines into an array of strings, then sorted with a comparison function chosen by mode:

  • Alphabetical uses the locale-aware localeCompare, optionally folding case.
  • Numeric parses the leading number of each line with parseFloat and compares the values, sending non-numeric lines to the end.
  • Length compares the character count of each line.
  • Reverse does no comparison at all; it simply flips the existing order.

The sort is stable, so equal lines keep their original sequence.

When to use each mode

Alphabetical is the go-to for any list where letter order matters: names, place names, glossary terms, URL slugs, or countries. Case-insensitive mode is usually the right default so “Zebra” doesn’t jump ahead of “apple” just because it is capitalised.

Numeric is essential for any list where the lines contain numbers. Without it, a plain alphabetical sort puts “10” before “2” because “1” comes before “2” as a character — numeric mode correctly orders 2, 9, 10, 100. It reads the leading number from each line, so lines like 12 items, 9 bags, and 100 units sort by the numeric value at the start.

Length is useful when you need to process short entries first (for example, fitting text into a fixed-width display) or when you want to scan the most verbose lines first when reviewing. It sorts by character count after any optional trimming.

Reverse simply flips whatever order the lines are currently in. Paste a list that is already sorted A to Z, hit Reverse, and get Z to A without running a comparison.

Practical examples

For example, sorting this raw priority list alphabetically (case-insensitive):

Zebra
apple
Mango
banana

Produces: apple, banana, Mango, Zebra — logical alphabetical order regardless of capitalisation.

For a version number list like v10.0, v2.1, v1.0, v9.5, numeric mode (which strips the leading v and reads the number) gives v1.0, v2.1, v9.5, v10.0 instead of the wrong v1.0, v10.0, v2.1, v9.5 that alphabetical sorting would return.

Common mistakes and edge cases

Trailing whitespace from spreadsheet pastes is the most common cause of unexpected sort order — a line ending in two spaces sorts differently from the same line without them. The trim option removes this reliably before comparison.

Blank lines are sorted as empty strings, which alphabetically come first. If you want to strip blank lines rather than keep them, run through the Duplicate Line Remover tool first, which also handles blank-line removal.

For CSV columns, this tool is not the right choice — it cannot parse delimiters or handle quoted fields. For plain comma-separated or tab-separated single-column data, paste one value per line and sort from there.