Sort Lines – Alphabetical, Natural & Random

Sort a list of lines A–Z, in natural order, by length, reverse it or shuffle it randomly.

Loading tool…

About the Sort Lines

A → Z sorts using the Unicode Collation Algorithm through Intl.Collator, so accented letters sort next to their base letters (é with e) instead of after z as a plain code-point sort would. Natural additionally compares digit runs as numbers, so file2.txt comes before file10.txt and item 9 before item 100.

Length orders lines from shortest to longest, with ties sorted alphabetically. Reverse order flips the list without sorting. Descending inverts the sort. Ignore case makes apple and Apple sort together; Unique only removes duplicates first.

Shuffle uses the Fisher–Yates algorithm with crypto.getRandomValues() and rejection sampling, so every order is equally likely. That is fair enough for picking raffle winners or randomising test order. Math.random() with sort() is biased. All processing is local.

Example: file10.txt, file2.txt, File1.txt sorted A → Z gives File1.txt, file10.txt, file2.txt, while Natural gives File1.txt, file2.txt, file10.txt.

How to use it

  1. Paste the lines to sort.
  2. Pick A → Z, Natural, Length, Reverse or Shuffle.
  3. Set descending, ignore case and unique options.
  4. Copy or download the sorted list.

Frequently asked questions

What is natural sort order?
Numbers inside text are compared by value, not digit by digit: 2 < 10, so file2 comes before file10. Plain alphabetical order puts file10 first.
Is the shuffle truly random?
It uses the browser's cryptographically secure random generator with an unbiased Fisher–Yates shuffle, so all permutations are equally likely.
How do I sort lines in the terminal?
sort file for alphabetical, sort -V for natural (version) order, sort -r to reverse and shuf to shuffle.

Related tools