What it does
Sort Lines by Length measures each line and reorders the list by that measurement. It does not change the text of any line. A line with trailing spaces is longer than the same line without them, which is why the trim option is on by default: it measures the content, not the accidental padding.
Length is counted in visible characters, using grapheme clusters. An emoji is one character, not a surrogate pair. A letter with a combining accent is one character. That makes the ordering match what a reader would call “long”, rather than what a byte-oriented tool would report.
This page is deliberately only about length. To sort whole lines alphabetically, by the last word, or by a CSV column, use the general line sorter instead.
Ties and stable order
Equal-length lines are sorted alphabetically as a tie-breaker. This is a small detail with a large effect: without it, the order of same-length lines would be arbitrary and could change from one run to the next. With it, the output is deterministic and easy to scan.
The alphabetical tie-breaker is locale-aware. In English, “apple” comes before “Banana” under a case-insensitive comparison; the exact ordering of accented letters depends on the browser’s collation. If you need a strict code-point order, sort the output again in a tool that exposes that choice.
Headers and duplicates
A header row is not part of the data. “Keep the first line as a header” takes the first line out of the sort and restores it at the top. It does not inspect the line to see whether it looks like a header; if you turn it on by accident, the first data row is treated as a title.
“Remove duplicate lines after sorting” is a convenience, not a replacement for a real deduplication pass. It removes exact duplicates after the edge spaces have been trimmed, and it runs after the sort so the shortest copy is the one that survives — which is usually the same as any other copy, but not always. For a careful dedupe with case and order controls, useRemove Duplicate Lines.
Examples
Before
The quick brown fox
A
jumped over
Two words
extraordinarily long lineAfter
A
Two words
jumped over
The quick brown fox
extraordinarily long lineThe one-character line comes first, then the two-word line, then the longer phrases. The ordering is by character count, not by word count, so “Two words” (nine characters) comes before “jumped over” (eleven characters).
Before
Product names
Mug
Notebook
Limited-edition enamel camping mugAfter
Product names
Limited-edition enamel camping mug
Notebook
MugThe header stays on top, and the longest product name rises to the top of the data. That is the line most likely to overflow a card, a table cell, or a fixed-width export.
Limits worth knowing
- Character length is not visual width. A wide letter such as W takes more horizontal space than an i, even though both count as one character. For a true visual fit, measure the rendered text in the target font.
- Trailing spaces count unless trimmed. The default trim keeps the measurement about the content. If the spaces are meaningful, turn it off and expect them to affect the order.
- Blank lines have length zero. In shortest-first mode they jump to the top unless removed. That is why “remove blank lines” exists as a separate choice.
- Sorting is not grouping. Lines of similar length end up near each other, but the tool does not create buckets or labels. It does not know that two lines are related just because they are the same length.
- Nothing is stored. A refresh clears the input and settings. Copy the result before leaving.
Page updated