Skip to main content
zerouploads

sort lines

file10 sorts after file9, the way you expect.

Case-insensitive, and file10 sorts after file9 rather than before.

The short answer

Sorted the way a person would: case is ignored, so Apple and apple sit together, and numbers inside a line are read as numbers, so file9 comes before file10. A plain sort puts file10 first, which is almost never what anyone wanted.

Sorts a list alphabetically, ignoring case and reading numbers as numbers. A plain sort puts file10 before file9, which is almost never what anyone wanted.

The formula

compare with the browser's locale rules, case-insensitive, numbers as numbers

Worked examples

file10, file9
file9, file10
Apple, apple
Apple, apple
Blank lines
dropped, not sorted to the top

Reference table

Where a plain sort and this one disagree
InputPlain codepoint sortHere
file9, file10file10, file9file9, file10
b, AA, bA, b
2, 1010, 22, 10
café, cafzcafz, cafécafé, cafz

How to use it

  1. 01Paste your linesOne item per line. Blank lines are dropped rather than sorted to the top.
  2. 02Copy the sorted listCase-insensitive, and numbers inside a line are compared as numbers.

Also searched for

Searches that land here include sort lines, alphabetize list, sort list online, line sorter and sort text alphabetically.

Sorting the way people read

Two sorts, two answers

Computers compare text by character code unless told otherwise, which produces an order that is consistent and unhelpful: every capital before every lowercase, every digit compared as a symbol. Locale-aware comparison exists to produce the other answer, the one a person would give, and it is what this page uses.

Numeric ordering is the one people notice

Filenames and version numbers are where a plain sort visibly falls apart. Ten screenshots named shot1 to shot10 come back as shot1, shot10, shot2, and every list of invoices numbered without leading zeros has the same problem. Reading the digits as a number fixes it without renaming anything.

Blank lines and what happens to them

They are dropped. A run of blank lines carries no order, and leaving them in would put a block of nothing at the top of the result. If the blank lines are structure rather than noise, sorting the list is going to destroy that structure anyway.

Questions people ask

Why does file10 come after file9 here?

Because the comparison reads the digits as a number rather than as characters. Character by character, the 1 in file10 sorts before the 9 in file9, which is why a plain sort produces file1, file10, file2. Comparing numerically gives the order a person would write.

Where do capitals end up?

Next to their lowercase equivalents. Apple and apple sit together rather than in two separate blocks, because a case-sensitive sort puts every capital letter before every lowercase one, which scatters a list of names or filenames in a way nobody finds useful.

How are accented letters sorted?

By their base letter, so café sorts among the other c words rather than after z. That is what the browser's own locale comparison does, and it matches how a dictionary or an index in a book is ordered.