Text · 52 tools · nothing uploads

Sort lines by length

Sort lines by length. Runs entirely on your device, nothing is uploaded.

Input

live

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

ToolRuns on the CLILive as you type
Sort lines by lengthYesYes
Number linesYesYes
Reverse linesYesYes
Shuffle linesYesYes
Unique lines with countsYesYes
Prefix or suffix linesYesYes
Extract linesYesYes

Related Text tools