After sorting, blank lines appeared at the top of my list; where did they come from and how do I get rid of them?

They were blank lines scattered through your list, and an empty line sorts before any text, so they all gathered at the top. «Remove empty lines» is on by default in the sorter, so if you see them it was most likely switched off: turn it back on and they are dropped with a count. If a line that looks empty still stays after that, it holds an invisible character.

Published · 3 min read

Where the blank lines came from

Copy a list out of an email, a Word file or a range of cells with some empties, and lines with nothing on them come along. In the original list they go unnoticed because they sit between items as separators. Sorting groups like with like, and an empty line is smaller than any text, so all those separators pile up at the start of the result.

A real example: تمر, a blank line, قهوة, a blank line, شاي. With the removal option off and Arabic rules, the output was two blank lines followed by تمر, شاي, قهوة. In descending order the reverse happens: the blank lines move to the bottom, where you may not notice them until you paste the result somewhere else.

The main fix: the remove-empty-lines option

  1. In the Line sorter, open «Sorting options» and make sure «Remove empty lines» is ticked. It is on when the page opens, but you may have switched it off earlier in the same session.
  2. Look under the result: the tool reports something like «2 empty lines removed», along with the number of input lines and lines in the result.
  3. Copy or download the result.

In the example above, with the option on, only three lines came out, تمر, شاي, قهوة, and the tool reported two empty lines removed. A line containing nothing but spaces counts as empty too and goes with them, because the tool looks for any visible character on the line.

A line that looks empty survived

The cause here is a character you cannot see that is not a space, such as the zero-width space (U+200B), which sometimes rides along when you copy from web pages or certain apps. The sorter does not count it as whitespace, so it treats the line as having content and puts it near the top because it starts with a symbol. I tested a list with one line holding only that character: with removal on, the line stayed and sorted first.

  • Paste the list into the Whitespace cleaner and turn on «Remove zero-width separators», which is off by default there.
  • Turn on «Show invisible characters in the preview» in the cleaner to see where the character was.
  • Copy the cleaned text and sort again; the line now counts as empty and is removed.

Do I ever want the blank lines?

If blank lines separate groups in your list, say coffee products then tea products, know that sorting will break the groups apart anyway: the sorter orders the whole list in one pass and knows nothing about groups. Sort each group on its own, then put them back together with the separators you want.

Common questions

Does the option remove the final line break at the end of the text?

A final line break at the very end is not counted as an empty line. The tool keeps it in the result if your input had one.

Does removing empty lines change anything in the other lines?

No. Lines with text come out exactly as they went in.