Sorting is not one operation

Ask for sorted lines and there are at least five different correct answers. Choosing the wrong one produces output that looks sorted and is not.

The two results that surprise people

item10 comes before item9. Default sorting is lexicographic — it compares character by character, left to right. At position five, the character 1 is lower than 9, so item10 wins and the digits after it are never examined:

LexicographicNatural
item1item1
item10item2
item11item9
item2item10
item9item11

Natural sort fixes this by detecting runs of digits and comparing them as numbers. It is what file managers use, and it is what you want for anything containing version numbers, chapter labels or filenames.

Zebra comes before apple. In ASCII and Unicode code-point order, every uppercase letter sits below every lowercase one — A is 65, Z is 90, a is 97. So a case-sensitive sort produces all the capitals first:

Apple, Banana, Zebra, apple, banana

rather than the case-insensitive result most people expect:

apple, Apple, Banana, banana, Zebra

Locale collation, where it gets genuinely hard

Alphabetical order is not a universal fact. It depends on the language:

Locale-aware comparison handles these; naive code-point comparison does not, and will place accented words in an order that looks arbitrary to a native reader.

Numeric sorting

Lines that are purely numbers must be compared as numbers, or you get 1, 10, 100, 2, 20, 3. Watch for negative signs, thousands separators, and decimal commas versus points — 1,5 is one and a half in much of Europe and fifteen hundred elsewhere, and no sorter can tell which you meant without being told.

The other operations that belong here

Honest limits

Sorting discards structure. If your lines are CSV rows with a header, sorting moves the header into the middle of the data — remove it first. If a record spans multiple lines, line sorting destroys it. Blank lines cluster at the top in most orders and are easy to miss.

Stability matters too: a stable sort preserves the original relative order of lines that compare equal, which is what makes multi-pass sorting work — sort by the secondary key first, then the primary. An unstable sort makes that technique unreliable. And for very large inputs, browser-based sorting is limited by memory; command-line tools handle files that will not fit in RAM by sorting in chunks.

Questions people actually ask

Which sort should I default to?

Case-insensitive natural sort matches human expectation most often. Use strict lexicographic only when you specifically need byte order, such as when matching another system output.

Why do my lines change after sorting even with no duplicates?

Usually invisible characters — trailing spaces, tabs, or Windows carriage returns at line ends. Trimming before comparison resolves nearly all of these.

Can I sort by a column?

Not with plain line sorting. You need a delimiter and a field index, which is what a spreadsheet or a command-line tool with field support gives you.

Is my text uploaded?

No. Sorting happens in your browser and nothing you paste is transmitted or stored.

Keep exploring Gen Code Tools

Every tool comes with a written guide, and every category is one click away.