LocalToolkit
HomeText Tools › Sort Lines

Sort Lines

Including natural order, which is what you wanted when file10 sorted before file2.

🔒 Runs in your browser. Nothing is uploaded — verify it in the network panel, or disconnect and try again.

Why plain alphabetical sort puts file10 before file2

A naive sort compares character by character. It reaches 1 in file10 and 2 in file2 and concludes that 1 is smaller, so file10 comes first. That is correct for text and wrong for anything humans number. Natural sort changes the rule: runs of digits are compared as numbers, so file2 precedes file10, and img1, img2, img12 come out in the order anyone reading the list expects.

The comparison options and what each one does

ModeBehaviourTypical use
Alphabetical (case-sensitive)Uppercase sorts before every lowercase letterReproducing byte-order output
Alphabetical (case-insensitive)Case is folded before comparingCleaning human-written lists
NaturalDigit runs compared numericallyFilenames, version numbers, page labels
NumericWhole line parsed as a numberPrice or count columns
By lengthShortest firstFinding outliers in a keyword list
ReverseAny of the above, reversedTop-N lists

Accented characters and why ü lands in odd places

Default sorting compares Unicode code points, which puts every accented Latin letter after z. Zebra then precedes apple with an umlaut, and a German user finds the list broken. The fix is collation — comparing according to a language's rules — which is what the locale-aware option does. For English lists, case-insensitive code-point order is usually close enough; for anything user-facing in another language, use locale collation.

Stability, and what happens to equal lines

A stable sort preserves the relative order of lines that compare equal. This matters when you sort by one key but the list already carries a meaningful order from a previous pass — for example sorting a product list by price when it was already grouped by category. Sorts here are stable, so equal lines stay in their original sequence.

Practical notes

How to use it

  1. Paste one item per line.
  2. Choose the comparison: alphabetical, natural, numeric, or by length.
  3. Toggle case sensitivity and blank-line handling.
  4. Copy the sorted output.

Worth knowing

  • Natural sort compares digit runs numerically, so file2 precedes file10.
  • Code-point order places accented Latin letters after z, which is why locale collation exists.
  • Sorts are stable, so equal lines keep their original relative order.
  • Blank lines can be dropped, kept in place, or pushed to the end.

Limitations

  • Numeric mode parses the entire line as one number and ignores trailing text.
  • Locale collation depends on the browser's available collation data.
  • Very large lists are limited by tab memory, though sorting is the cheap part.
  • Mixed-language lists have no single correct order.

Frequently asked questions

Why does file10 sort before file2?
Because a plain alphabetical comparison compares characters and 1 is less than 2. Choose natural sort to compare digit runs as numbers instead.
Can I sort by more than one column?
Indirectly: sort by the secondary criterion first, then apply the primary sort. Because the sort is stable, the earlier ordering is preserved within groups of equal primary keys.
How do I sort a list of names with accents?
Use the locale-aware option. Plain code-point order treats É as greater than Z, which is not what a French reader expects.
Does sorting remove duplicates?
No. It reorders. Use the duplicate remover first if you want a unique list, or the deduplication tool if you want repeated values adjacent.
Related tools
Remove Duplicate LinesWord Frequency CounterCase ConverterWord and Character CounterURL Slug GeneratorLorem Ipsum Generator
Keep reading
How browser-only processing worksAll Text Tools toolsEvery tool on the site