Utility · April 2026 · 5 min read

The Complete Guide to Sorting Text Lines

'Alphabetical' sorting trips up thousands of people every day because it's not one thing. Here's when to use each sort mode — and why your spreadsheet keeps putting 'Item 10' before 'Item 2'.

Why Simple Alphabetical Sort Isn't Always What You Want

If you sort this list alphabetically: Item 1, Item 2, Item 10, Item 20 — you get Item 1, Item 10, Item 2, Item 20. That's not wrong. It's just how character-by-character sorting works. The character "1" comes before "2", so "Item 10" comes before "Item 2".

This surprises people constantly. The fix is natural sort (also called numerical sort) — it reads digit sequences as numbers, not characters. Under natural sort, "Item 2" correctly comes before "Item 10".

The 8 Sort Modes Explained

A → Z (alphabetical ascending)

Standard dictionary order. Uses locale-aware comparison, so accented characters sort correctly in the current language. "é" sorts with "e", "ñ" sorts with "n". Perfect for names, titles, and general-purpose listing.

Z → A (alphabetical descending)

Reverse dictionary order. Useful for finding the last items alphabetically — last names, newest-looking items by date strings, etc.

1 → 9 (numerical natural order)

Reads number sequences as numbers. Use for: version numbers (v1.2, v1.10, v2.0), file names with counters (IMG_001, IMG_020, IMG_100), ranked lists. If you see "10" appearing before "2" in your output, you want natural sort instead.

9 → 1 (natural descending)

Highest numbers first. Useful for rankings, timestamps, newest entries.

Shortest first / Longest first

Sorts by character count. Useful for spotting outliers (shortest URL, longest error message), or arranging items for visual hierarchy. In log analysis, longest lines are often the most detailed error messages.

Reverse order

Flips the existing order without sorting. If your file is in chronological order, reverse gives you reverse chronological. No sorting logic is applied — it's purely positional.

Shuffle

Randomizes order. Uses the Fisher-Yates algorithm for unbiased shuffling. Use for: giveaway draws, randomizing test questions, creating random playlists.

Case Sensitivity Matters

By default, sorting is case-insensitive — "apple," "Banana," and "Cherry" interleave naturally. Turn on case-sensitive sort when you need ASCII order, where uppercase letters (A-Z) all come before lowercase (a-z). In ASCII order: "Banana" < "apple" because uppercase B (ASCII 66) is less than lowercase a (ASCII 97).

International Characters

The tool uses Intl.Collator, which respects your browser's locale. For English users, "ö" sorts after "o". For German users, "ö" might sort after "z" depending on settings. This is usually what you want — sort matches the user's expected alphabet.

Pro tip: To sort a CSV by a specific column, first extract just that column into a list, sort it, then use the sorted list as an index to reorder the full CSV. Our CSV Viewer handles in-place column sorting automatically.

Sort Before You Deduplicate

If you're cleaning data, sort first, then deduplicate. Sorting groups similar items together, which makes duplicate patterns visible even before you run deduplication. You'll catch near-duplicates that exact-match deduplication would miss.

Try the tool

8 sort modes, international support, runs in your browser.

Open Sort Lines →

Frequently Asked Questions

Why does '10' sort before '2' alphabetically?
Character-by-character sorting reads '1' before '2', so '10' (starting with 1) comes before '2'. Switch to numerical/natural sort to treat number sequences as actual numbers.
Does it handle international characters?
Yes. The tool uses browser-native locale-aware comparison, so accented characters, non-English alphabets, and mixed-language text all sort correctly.
Is shuffle cryptographically random?
No. Shuffle uses Math.random() which is fine for casual randomization (giveaways, playlists). Don't use it for anything where true randomness matters — like cryptographic key generation.
Can I sort by multiple criteria?
Not directly. For multi-key sorting (e.g., 'sort by last name, then first name'), you'd need a spreadsheet tool. This tool sorts one dimension at a time.

Published April 2026 by Derek Giordano