Back to Tools

Sort Text by Length

Organize lines based on character count

0
0
0
Input Lines

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

  1. Add your lines to the Input Lines box by typing, pressing Paste, importing a .txt file with File, or loading the Sample fruit list.
  2. Pick a direction with the radio buttons: Short to Long or Long to Short.
  3. Keep Trim lines and Skip blank ticked if you want spaces at line ends and empty rows ignored. Both are on by default.
  4. Click Sort by Length. The summary tells you how many lines were sorted and in which direction.
  5. 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


Frequently Asked Questions

Does it sort alphabetically as well?
No. The only sort key is the number of characters in the line. Lines with the same length stay in their original order rather than being alphabetized, so run a separate alphabetical sorter if you need that too.
Are spaces counted in the line length?
Yes, every character counts, including spaces inside the line. With Trim lines ticked, spaces at the beginning and end are removed first, so they do not affect the ranking. Untick it to count them.
Where do empty lines go?
If Skip blank is ticked, they are removed. If it is off, empty lines have length zero, so they appear first when sorting short to long and last when sorting long to short.
Can I sort by word count instead?
Not with this tool. It compares character counts only. The stats above the input show total words, but the sorting order is based on how many characters each line contains.
Can I load a text file?
Yes, the File button accepts .txt files and places the contents in the input box. Then choose your direction and click Sort by Length. The sorted output can be copied or downloaded as a TXT file.
Support Chat
We typically reply within minutes

Hello! 👋 Before we start, please tell us your name.