Sort Lines
Including natural order, which is what you wanted when file10 sorted before file2.
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
| Mode | Behaviour | Typical use |
|---|---|---|
| Alphabetical (case-sensitive) | Uppercase sorts before every lowercase letter | Reproducing byte-order output |
| Alphabetical (case-insensitive) | Case is folded before comparing | Cleaning human-written lists |
| Natural | Digit runs compared numerically | Filenames, version numbers, page labels |
| Numeric | Whole line parsed as a number | Price or count columns |
| By length | Shortest first | Finding outliers in a keyword list |
| Reverse | Any of the above, reversed | Top-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
- Sort ignores or preserves blank lines according to your choice; leaving them in place usually scrambles visual grouping.
- Leading whitespace affects comparison — trim first if a list came from a spreadsheet.
- For a two-key sort (by category, then by name), sort by the secondary key first, then by the primary one, relying on stability.
- Sorting thousands of lines is instant; the comparison function is the only cost.
How to use it
- Paste one item per line.
- Choose the comparison: alphabetical, natural, numeric, or by length.
- Toggle case sensitivity and blank-line handling.
- Copy the sorted output.
Worth knowing
- Natural sort compares digit runs numerically, so
file2precedesfile10. - 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?
1 is less than 2. Choose natural sort to compare digit runs as numbers instead.Can I sort by more than one column?
How do I sort a list of names with accents?
É as greater than Z, which is not what a French reader expects.