← All tools

Stays in your browser

Sort Lines Online — Sort, Dedupe, Shuffle

Free line sorter. Sort ascending/descending, remove duplicates, reverse, or shuffle lines.

Sorting text as data

Sorting is only well defined once you decide the collation. Case-insensitive ordering places a lowercase word next to its capitalised form, while code-point ordering places every uppercase letter before every lowercase one. Neither is wrong, but picking the wrong one for the data is.

Numbers are the other trap. Comparing digits as characters puts 10 before 9, so a list of file names or versions looks broken even though the algorithm did exactly what it was told. Numeric-aware comparison or zero-padding the values is the fix.

Deduplication has the same problem. Two lines that differ only by trailing whitespace or case are different strings and both survive a naive dedupe while looking identical on screen. Trim first, then decide whether the comparison should be case-sensitive, and dedupe after sorting rather than before.

FAQ

How is sorting ordered?
localeCompare — good for common letters and numbers.
Which duplicate is kept?
The first occurrence.
Is text uploaded?
No.
Why does 10 sort before 9?
Because the comparison is textual: the character 1 comes before 9, so any number starting with 1 sorts earlier regardless of its magnitude. Pad numbers to a fixed width or use a numeric comparison when the values are actually numbers.
How do I remove duplicate lines?
Sort first, then remove adjacent duplicates, which is far cheaper than comparing every line with every other. Trim whitespace before comparing, otherwise lines that look identical will both be kept because one has a trailing space.
Does sorting here change the case of my text?
No. Comparison is locale-aware and does not modify the lines, so the original casing and spacing are preserved in the output. Only the order changes, which means you can sort, inspect, and sort back without losing anything.

Related tools