ToolBook
Support us on Ko-fi
Help us keep this free, forever

Sort Lines

How to sort lines online

Paste your list, pick a sort mode, copy the result. Eight modes, instant output.

  1. Paste your list

    Drop the lines into the input box. Names, URLs, log entries, filenames, version numbers, any list with one entry per line.

  2. Pick a sort mode

    Choose A → Z, Z → A, by length, numeric, reverse, or shuffle. Eight modes total. The output panel updates instantly.

  3. Tune the comparison

    Toggle case sensitivity for strict matching. Keep natural sort on for filenames and versions. Add trim whitespace or remove blanks if the paste is messy.

  4. Copy the sorted output

    The output panel renders the sorted list in real time. Click Copy to grab the whole thing for your editor, spreadsheet, or chat.

Frequently asked questions

How do I sort lines alphabetically online?

Paste the list into the input box and pick "A → Z" or "Z → A". The output panel sorts the lines instantly. Keep natural sort on if the entries contain embedded numbers (filenames, versions); leave case-sensitive off for the intuitive "Apple, apple" grouping most people expect.

Does this sort numbers correctly?

Yes. Pick "Numeric ↑" or "Numeric ↓" and lines with leading numeric values are compared as numbers. So 2, 10, 1 sorts as 1, 2, 10 instead of 1, 10, 2 like a plain string sort would. Lines that are not numeric fall to the bottom.

What is natural sort and when should I use it?

Natural sort treats embedded numbers as numbers, so "file2.png" comes before "file10.png" the way a human reads them. The toggle uses JavaScript's Intl.Collator with the numeric option, which is the same algorithm macOS Finder and Windows Explorer use for filenames. Keep it on for filenames, version strings (v1.2.10), and episode lists.

How does sort by length work?

Pick "Short → Long" or "Long → Short" and the lines reorder by character count. Useful for spotting outliers in a list, organizing variable-length tags, or finding the longest URL in a sitemap dump.

Can I trim whitespace and drop blank lines before sorting?

Yes. Toggle "Trim whitespace" to strip leading and trailing spaces on every line, and "Remove blanks" to drop empty lines from the output. Combine them when sorting pasted data that has stray indentation or empty rows from a spreadsheet export.

Are duplicates removed when I sort?

No. Sorting preserves every line, even duplicates, so they appear next to each other. To remove duplicates, run the output through ToolBook's Remove Duplicate Lines tool. Splitting these into two tools keeps each one fast and predictable, and lets you sort while keeping duplicates for frequency analysis.

Is the shuffle truly random?

Shuffle uses Fisher-Yates with a deterministic pseudo-random generator seeded from the current time, which is plenty random for human use (rearranging a brainstorm, randomizing draft order, scrambling a quiz answer key). Do not use it for cryptographic randomness, since the underlying LCG is not crypto-grade.

Why does case-sensitive sorting put uppercase before lowercase?

In ASCII and the Unicode Basic Latin block, uppercase letters have lower code points than lowercase. So a strict byte-level sort puts "Apple" before "apple" and "Z" before "a". Toggle case sensitivity off for the more intuitive "Apple, apple, Z" behavior most people expect.

Is there a limit on how many lines I can sort?

Sorting runs entirely in your browser, so the practical limit is your device memory. Lists of a few hundred thousand short lines sort in well under a second on a modern laptop. Nothing is uploaded to a server.

Sorting lists, the right way

Eight sort modes, when to use natural sort, and why sort and dedupe are different jobs.

Sorting is one of those things that looks trivial until you need it

Open a list, sort it. That's the whole job. The reason "sort lines online" is a real search query, instead of "use sort -u in your terminal", is that the people who need it most aren't on a terminal. They're in a CMS, an email client, a Google Docs comment, or a spreadsheet that won't sort the way they want.

This page handles every common case: alphabetical, alphabetical reverse, by length, by length reverse, numeric, numeric reverse, document-order reverse, and shuffle.

The "natural sort" thing

A plain string-sort puts file10.png before file2.png because it compares character by character, where '1' beats '2' as a single character regardless of what follows. Humans read those filenames as numbers and expect 2 < 10. Natural sort fixes the gap.

The toggle on this tool uses JavaScript's Intl.Collator with the numeric: true option, which is the same algorithm macOS Finder, Windows Explorer, and most modern CLIs use. It detects embedded numeric runs and compares them as numbers, so v1.2.10 correctly sorts after v1.2.9 and chapter-2-the-fall.md sorts before chapter-10-the-rise.md.

Keep it on for filenames, version numbers, episode lists, and anything where embedded numbers should be ordered numerically. Turn it off only if you want strict character-by-character comparison.

When to use numeric sort instead of alphabetical natural

Numeric sort treats each whole line as a single number, so the leading numeric value wins and the rest of the line is a tiebreaker. Use this when every line starts with a number and the number is what you care about: leaderboard scores, prices, line numbers from a log, ranks.

Natural alpha sort treats each line as a string with embedded numbers. Use this when the line is a string that happens to contain numbers: filenames, version strings, episode titles.

The two modes look identical for clean numeric lists. They diverge the moment you have lines like 2nd place vs 10th place (numeric mode reads the leading number; alpha-natural reads the whole string and orders the same way).

Sort doesn't dedupe

Sorting puts duplicates next to each other but does not remove them. If you want unique sorted output (the classic sort -u), run the result through Remove Duplicate Lines afterwards. Two operations, two tools, one paste between them.

We chose to split these instead of bundling because each operation is independently useful. Sometimes you want to sort and keep duplicates (frequency analysis), sometimes you want to dedupe without sorting (preserve original order). One combined "sort + unique" tool would force the wrong default in half the cases.

The shuffle case

Shuffle randomizes line order using a deterministic pseudo-random generator. Same seed = same output. Hit "Shuffle" again to bump the seed and get a fresh permutation.

Don't use this for security-critical randomness. The LCG algorithm is fast and good for human use cases (rearrange a brainstorm list, randomize draft order, scramble a quiz answer key) but isn't crypto-grade. For cryptographic shuffling, use a real RNG in code.

Sort is also how you find anomalies

A surprising use of sort: spotting outliers. Sort a list of file sizes by length and the giant entries jump to the top. Sort a list of error messages alphabetically and identical errors cluster. Sort a list of timestamps and the gaps reveal time skips. The pattern is "sort, then scan": sort makes the data legible to a quick visual pass.

This is one of the reasons every grizzled engineer reaches for sort in a shell pipeline. You're rarely sorting because the order itself matters; you're sorting because the next operation works better on sorted data.