TextyConverterbeta
⌘K

Sort by Line Length

Sort lines by character count — shortest first or longest first. Unicode-aware.

About Sort by Line Length

This tool orders lines by their character length. By default the shortest line comes first, but you can flip the order with a single toggle. Length is measured in Unicode code points, so emoji count as one character each.

When to use it

  • Producing a 'short to long' or 'long to short' inventory of items
  • Finding the longest entry in a list
  • Bucketing data by approximate size
  • Visualizing the length distribution of a column

How it works

Lines are split on LF/CRLF, empty lines are dropped, and the array is sorted by Array.from(line).length. Ties are broken by alphabetical order.

Examples

Ascending by length
banana
apple
strawberry
apple
banana
strawberry

Frequently asked questions

Is length measured in characters or bytes?
Unicode code points. Emoji and most CJK characters count as one each, even though they take more than one byte in UTF-8.
How are ties broken?
Alphabetically. Two lines of the same length appear in alphabetical order relative to each other.

Related tools