Sort Lines
Put any list in order: alphabetically in either direction, in natural order, by the first number on each line, by length, or in a random shuffle. Sorting uses your browser's own language rules and runs entirely on your device.
0 characters · 0 words · 0 lines
0 characters · 0 words · 0 lines
Runs entirely in this browser tab. Your text is never uploaded or stored.
What it does
Sort Lines reorders lines alphabetically with your browser's locale-aware collation, in natural order (file2 before file10), by the first number in each line, by length, or in a random shuffle.
item 10 item 9 Item 1
Item 1 item 9 item 10
Alphabetical is not the same as character code order
The simplest way for a computer to sort text is by character code, and that gives odd results: every capital letter (codes 65 to 90 in ASCII) comes before every small letter (97 to 122), so "Zebra" sorts ahead of "apple", and accented letters land after z. People expect dictionary order instead, which is what linguists call collation. This tool uses Intl.Collator, the browser's implementation of the Unicode Collation Algorithm, so "apple", "Banana" and "éclair" sort the way a reader expects.
Collation also depends on language. German dictionaries file ä with a, while Swedish places å, ä and ö after z, at the very end of the alphabet. The tool uses the default locale of your browser, so a list sorted on a Swedish system follows Swedish rules. With ignore case on, letters that differ only in case or accent compare as equal and are ordered by the next difference.
Natural, numeric and length order
Alphabetical order compares digits one at a time, so "file10" comes before "file2" because 1 is smaller than 2. Natural order reads runs of digits as whole numbers and gives file1, file2, file10, the way file managers such as Windows Explorer and the macOS Finder display names. Use it for chapter titles, version lists, invoice numbers and photo names like IMG_9 and IMG_10.
Numeric order looks for the first number in each line, including a minus sign and decimals, and sorts by its value, which suits price lists, scores and lines such as "12 apples". Lines without a number go to the end. Length order sorts by the number of visible characters, shortest first, with ties broken alphabetically; it is useful for finding the shortest domain names or spotting truncated entries.
How the shuffle works
Shuffle uses the Fisher–Yates algorithm (published by Ronald Fisher and Frank Yates in 1938 and adapted for computers by Richard Durstenfeld in 1964), which walks the list from the end and swaps each line with a randomly chosen line at or before it. With a good random source every ordering is equally likely. The random numbers come from mulberry32, a small seeded pseudo-random generator, so a shuffle stays the same until you ask for a new one. Because its state is 32 bits, it can produce at most about 4.3 billion different shuffles, fewer than the 6.2 billion orderings of just 13 lines. That is fine for quiz questions, playlists and picking a presentation order, but not for lotteries or anything with money or security at stake.
To clean a list before sorting, run it through Remove Duplicate Lines first.
Frequently asked questions
- Why does file10 sort before file2?
- Plain alphabetical order compares character by character, and 1 comes before 2. Choose natural order, which treats each run of digits as a number, to get file2 before file10.
- Does sorting put uppercase words first?
- No. Sorting uses language-aware collation, so apple and Apple sit next to each other. Only simple character-code sorting puts all capital letters before all small ones.
- Is the random shuffle truly random?
- It uses an unbiased Fisher–Yates shuffle driven by a fast seeded pseudo-random generator. That is fair enough for everyday use but not suitable for draws, lotteries or security.
- Where do lines without a number go in numeric order?
- To the end of the list, in alphabetical order among themselves. Lines that do contain a number are ordered by the value of the first number found on the line.
- Can I sort lines in reverse alphabetical order?
- Yes, choose Z→A. It uses the same language-aware comparison as A→Z, simply reversed, so accented and capitalized words stay in sensible positions.