Sort Lines

Sort lines alphabetically, numerically or by length.

Free line sorter — order lines alphabetically (A–Z or Z–A), numerically, or by length, with optional case-insensitive comparison. Runs entirely in your browser, nothing is uploaded. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

What sort orders are supported?

Alphabetical A–Z and Z–A, numeric low-to-high and high-to-low, and by line length (short to long). Alphabetical sorting can additionally be made case-insensitive.

Paste a list and reorder it alphabetically, numerically, or by line length — ascending or descending. It is built for cleaning up word lists, CSV columns, log snippets, config keys, and any one-item-per-line data.

Sort keys and comparison options

The text is split on line breaks into an array, then sorted by the mode you pick:

  • Alphabetical (A → Z / Z → A) uses localeCompare, your browser’s language-aware string comparison, so accents and non-Latin scripts order naturally. With case-insensitive enabled, both lines are lowercased before comparing, so Apple and apple group together.
  • Numeric (low → high / high → low) parses the leading number of each line. A line that does not begin with a number is treated as positive infinity, which pushes all non-numeric lines to the end.
  • Line length (short → long) compares the character count of each line.

The case-insensitive toggle only affects alphabetical sorting.

Example

Input lines: banana, apple, cherry, date

Alphabetical (A → Z) output:

apple
banana
cherry
date
ModeResult order
Alphabetical A→Zapple, banana, cherry, date
Alphabetical Z→Adate, cherry, banana, apple
Length (short→long)date, apple, banana, cherry

All sorting happens in your browser; nothing is uploaded.

When line sorting is genuinely useful

Config key ordering. Environment variable files, YAML keys, and .properties files become easier to scan and diff when their keys are alphabetical. Paste the section, sort A → Z, paste it back. Git diffs against future changes stay compact.

Deduplication prep. Alphabetical sorting groups identical lines together so duplicate entries are visually obvious before you run a deduplicate step. It is a useful first pass on any list you suspect has repeats.

Log analysis. If you paste a list of extracted hostnames, IP addresses, or error codes, sorting numerically or alphabetically surfaces clusters quickly — for example, all 10.0.* addresses will group together after numeric or alphabetical sort.

Prioritised task lists. When brainstorming, writers and project managers often dump items in random order. Sorting by length can create a natural visual staircase, or alphabetical sorting groups similar topics.

Edge cases to know

  • Blank lines are preserved and sort to the top in alphabetical mode (because an empty string comes before any character) and to the bottom in length mode. Remove them first with a blank-line stripper if they interfere.
  • Leading whitespace counts. A line starting with a space sorts before A alphabetically. Strip leading whitespace if you want pure word order.
  • Numbers with leading zeros. 007 parses as the number 7 in numeric mode, so 007 and 7 sort together. This is usually correct, but can be surprising for zero-padded IDs you want treated as strings — use alphabetical mode instead.
  • Very large lists (tens of thousands of lines) sort in a fraction of a second in modern browsers because the underlying JavaScript sort is highly optimised.

Lexicographic vs natural: why “file10” sorts before “file2”

Plain lexicographic sorting compares character by character, so file10 lands before file2 — the string “1” is smaller than “2” and the comparison never reaches the digits’ numeric meaning. Natural sort fixes this by grouping digit runs and comparing them as numbers, producing file1, file2, file10. Use natural sort for anything with embedded numbers (filenames, versions, invoice IDs) and lexicographic for strict byte-order requirements (binary search over a sorted file, comparing against the output of other tools).

Locale, case and stability

Three details separate a careful sort from a surprising one:

  • Case sensitivity. In pure code-point order, all uppercase letters sort before all lowercase (Z < a), which scatters a mixed-case list. Case-insensitive mode compares the folded forms and keeps apple and Apple adjacent.
  • Accents and locale. Characters like é and ö sort after z by raw code point, which is wrong for most languages. Locale-aware collation as defined by the Unicode Collation Algorithm fixes this; browsers expose it via Intl.Collator.
  • Stability. A stable sort preserves the input order of lines that compare equal — so sorting case-insensitively never arbitrarily reorders Apple/apple pairs. JavaScript’s built-in sort has been guaranteed stable since ES2019.

The command-line equivalents

If you need the same operations in a pipeline, POSIX sort covers most of them: sort -f folds case, sort -r reverses, sort -u deduplicates while sorting, and GNU sort’s -V gives a version/natural-style ordering. The browser tool’s advantage is interactivity — you see the result instantly, adjust one toggle, and never risk overwriting a file with a wrong flag.

Sorting as a preprocessing step

Sorting rarely stands alone — it is the step that unlocks the next tool. Sorted input turns duplicate detection into an adjacency check (uniq’s whole premise), makes two lists comparable side-by-side for spotting missing entries, groups related items (all URLs from one domain cluster together), and produces deterministic output for reproducible builds and clean diffs. When a config file, dependency list or translation file is alphabetised before every commit, review diffs show what changed instead of what moved — which is why many teams enforce sorted order with a linter and why “sort, then diff” is the fastest manual way to compare two exports of the same data.

And when the sorted list is destined for a spreadsheet, sort before pasting rather than after: spreadsheet sorts operate on whole rows and can silently decouple a column from its neighbours, while sorting the raw lines here keeps each line atomic and intact.