Sort Text by Length
Organize lines based on character count
Order lines by how long they are
Alphabetical sorting is common, but sometimes the useful order is by size: the longest sentence in a draft, the shortest keyword in a list, or the widest label that will not fit a column. This tool counts the characters in each line and sorts the whole list by that number, either from the shortest line up or from the longest down.
Using the tool
- Add your lines to the Input Lines box by typing, pressing Paste, importing a .txt file with File, or loading the Sample fruit list.
- Pick a direction with the radio buttons: Short to Long or Long to Short.
- Keep Trim lines and Skip blank ticked if you want spaces at line ends and empty rows ignored. Both are on by default.
- Click Sort by Length. The summary tells you how many lines were sorted and in which direction.
- Use Copy or .TXT to take the result away as sorted-by-length.txt.
How length is measured
The measure is the number of characters in the line as it exists after your options are applied. That is why Trim lines matters: with it off, a line with trailing spaces counts as longer than the same line without them. Lines that tie keep their original relative order in current browsers, so sorting is predictable. Some emoji and rare symbols occupy two units in JavaScript strings, so a line full of emoji can count as longer than it looks.
Use cases
- Finding the longest headlines or meta descriptions in a batch so you can shorten them.
- Ordering a word list from short to long for puzzles, spelling drills or anagram sets.
- Sorting lines of code or log entries to spot unusually long ones.
- Preparing a list where you want the most compact items first, such as button labels or tags.
Limitations
- This is a length sort only. Lines of equal length are not alphabetized.
- Words within a line are not reordered; the whole line moves as one unit.
- Length counts characters, not words. A line of two long words can outrank a line of five short ones.
- Leaving Skip blank off puts empty lines at the top in Short to Long mode, since their length is zero.
All of this runs as JavaScript in the page, and the Before and After panels show character, word and line totals so you can confirm the content is intact.
Related Tools
Related Tools