HomeText & Developer Tools › Sort Lines

Sort Lines

Paste a list and sort it alphabetically, in reverse, by line length, in natural numeric order, or shuffle it at random - with optional blank-line removal and deduplication.

     

What the seven orders do

Ascending and descending compare the lines character by character. With Ignore case checked you get the dictionary order most people expect; unchecked, the comparison uses raw character codes, which puts every capital letter ahead of every lowercase one, so Zebra lands before apple. Natural numeric uses the browser's locale-aware comparison with numeric collation turned on, so embedded numbers are compared as numbers: chapter2 comes before chapter10 instead of after it. That is the order Windows Explorer and macOS Finder use for file names, and it is the right choice for episodes, versions, invoice numbers and SKUs.

Shortest first and longest first sort by character count and break ties alphabetically - useful for spotting a truncated row in a data export or finding the longest keyword in a list. Reverse flips the order you already have without sorting anything, which is how you turn a chronological log upside down. Shuffle applies a Fisher-Yates shuffle, walking the list from the end and swapping each item with a randomly chosen earlier one; that produces every permutation with equal probability. Keep original order is for when you only want the clean-up options.

Clean-up options and the order of operations

The steps always run in the same sequence: trim spaces, remove blank lines, remove duplicates, then sort. Trimming first matters, because apple and apple  with a trailing space are different strings and would otherwise both survive deduplication. Duplicate removal keeps the first occurrence and drops the later copies; with Ignore case checked, Chapter2.mp3 and chapter2.mp3 count as the same entry.

The sample list has 9 lines including one blank line and one exact duplicate. With the default settings - trim on, blanks removed, duplicates kept, ignore case, ascending - you get 8 lines and Chapter10.mp3 sorts between chapter1.mp3 and chapter2.mp3, because plain alphabetical order compares the character 1 then 0 against 1 then dot. Switch to natural numeric and the same list comes out 1, 2, 2, 3, 10, 20, which is almost always what you actually wanted.

Tips

To alphabetize a spreadsheet column, copy the column, paste it here, sort, and paste it back - faster than building a sort key in Excel when you only need it once. To sort comma-separated values, replace the commas with line breaks first. Lists of a few hundred thousand lines sort in well under a second in a modern browser. Everything runs locally, so customer lists, internal URLs and unreleased file names never leave your computer.

Frequently asked questions

Why does capital Z sort before lowercase a?

Because plain character-code order puts all uppercase letters (65-90) before all lowercase ones (97-122). Check Ignore case for dictionary order, or use natural numeric sorting.

What exactly is natural sort?

It reads runs of digits inside a line as numbers instead of text, so item2 sorts before item10. It is the same rule file managers use to order numbered files.

Is the shuffle random enough for a raffle?

It is an unbiased Fisher-Yates shuffle driven by Math.random, which is fine for choosing a presentation order or a casual draw. For anything with money at stake, use a method with cryptographic randomness or a witnessed physical draw.

Does it keep my original text if I make a mistake?

Your input box is never modified, so you can change the options and sort again from the original at any time. The sorted output appears below and has its own copy button.