{}DevStringToolsAll tools

Sort Lines

Sort lines of text alphabetically, numerically (natural number sort), by length, or in reverse order. Optional deduplication and case-insensitive modes.

53 chars

How Sort Lines works

Sort Lines takes a list of newline-separated strings and reorders them using one of four comparators: alphabetical (with optional case-insensitivity), numerical natural order (so "item2" comes before "item10"), by line length, or in reverse. A separate option collapses duplicate lines while preserving the order of first occurrence.

How to use

Paste a list, pick a sort mode, and watch the output reorder live. Combine with "Remove duplicates" for a unique sorted list. Useful for cleaning CSV rows, log lines, tag lists, and SQL IN clauses.

Frequently asked questions

How does numeric (natural) sort differ from alphabetical sort?

Natural sort treats embedded numbers as values rather than characters. "item2" comes before "item10" naturally, whereas alphabetical sort would place "item10" first because "1" < "2". The natural comparator is ideal for filenames, version strings, and log lines.

Will case-insensitive sort still capitalise properly?

Yes. The sort uses a case-insensitive comparison but keeps your original casing in the output. "Banana" and "apple" sort as "apple, Banana" — same as if you had typed "APPLE, banana" originally.

Does the output stay stable for items that compare equal?

Yes. Sort Lines uses a stable algorithm, so items with equal keys remain in their original relative order. This matters when deduplicating — the first occurrence wins.

Can I sort a CSV without breaking rows?

Only if every row is exactly one line. Multi-line cells (quoted strings with embedded \n) will be split across rows and treated as separate sort keys. For multi-line CSVs, sort by a single column in a spreadsheet or script instead.

Why does reverse not undo a forward sort?

Reverse is a standalone comparator that inverts the default alphabetical order; it is not the strict inverse of any other mode. To flip a numerically sorted list, pick reverse, not numerical — reverse uses alphabetical fallback.