
Sort lines by length
Sort lines by length. Runs entirely on your device, nothing is uploaded.
Sort lines by length reorders a pasted text's lines from shortest to longest, measuring each by its character count. Lines of equal length keep their original relative order, since the sort is stable. A trailing newline in the input, if present, is preserved. Sorting is always ascending, so the longest line ends up last, not first.
Questions
What does it measure a line length by?
The number of characters in the line, using the string length directly, not word count or byte size. A line with wide Unicode characters is still measured by character count, not by how many bytes those characters happen to take up.
What happens to lines of the same length?
Their input order decides it: the sort is stable, so two lines of equal length are compared by original position and never swapped past each other.
Can I sort longest first instead?
Not directly. The sort always runs shortest to longest; getting the longest lines first means reading the output from the end, since there is no descending option.
Does sorting change any line's text?
No. Lines are only reordered; nothing inside a line is modified.
What happens to a trailing newline in the input?
It is preserved on the output, the same way it is across the other line-based tools in this group.
Compare
| Tool | Runs on the CLI | Live as you type |
|---|---|---|
| Sort lines by length | Yes | Yes |
| Number lines | Yes | Yes |
| Reverse lines | Yes | Yes |
| Shuffle lines | Yes | Yes |
| Unique lines with counts | Yes | Yes |
| Prefix or suffix lines | Yes | Yes |
| Extract lines | Yes | Yes |