Line Sorter

Sorts lines alphabetically, by length, numerically or into a genuinely random order, with an option to drop duplicates in the same pass. Useful for tidying lists, ordering CSV columns and turning an unstructured dump into something you can scan.

Live demo · real result from this tool

Sorted lines

9 pears 10 apples Apple apple banana cherry

Processed on your device — nothing is uploaded.

How to use Line Sorter

  1. Paste your lines.
  2. Choose the order: A→Z, Z→A, by length, numeric or random shuffle.
  3. Tick remove duplicates if you want them dropped in the same pass.
  4. Press Sort Lines and copy the result.
  5. Duplicate removal runs after sorting, and keeps the first of each group.
  6. Blank lines sort to the top in alphabetical mode — delete them first if that is noise.
  7. Leading whitespace is part of the line, so indented entries sort with the indentation included.

Alphabetical sorting is locale-aware

A to Z uses the browser’s locale comparison rather than raw character codes, so accented letters land where a reader expects rather than after z, and ä sorts next to a. Raw code-point sorting — what a naive implementation does — puts all uppercase before all lowercase, so Zebra comes before apple. Comparison here is case-insensitive, so apple, Banana and cherry interleave the way you would write them down.

Numeric sorting is not alphabetical sorting

Sorted as text, 10 comes before 9, because the comparison is character by character. The numeric mode parses the start of each line as a number instead, so 2, 9, 10, 100 sort properly. It reads the leading number and ignores the rest, which means lines like “3 apples” sort correctly but lines beginning with text do not sort at all — put the number first if you can.

Sorting by length, and shuffling

Length sorting is handy for spotting outliers: the malformed row in an export, the one URL with a tracking query attached, the password that got truncated. Random shuffle uses a Fisher–Yates pass, which produces every ordering with equal probability — worth stating because the common one-line trick of sorting with a random comparator does not, and leaves items suspiciously close to where they started.

Frequently asked questions

Does sorting ignore case?
Yes — case-insensitive sorting treats 'Apple' and 'apple' as equal.
Can I sort numbers?
Yes — numeric sort mode sorts lines that start with numbers correctly (1, 2, 10 not 1, 10, 2).
Does it remove blank lines?
Optional — you can strip blank lines before or after sorting.
Why is 10 sorting before 2?
Because alphabetical mode compares text, and the character 1 comes before 2. Switch to numeric mode, which parses each line as a number before comparing.
Does sorting change the text of my lines?
No — it only reorders them. Removing duplicates deletes whole lines but never edits the ones it keeps.
Is the random shuffle actually random?
Yes. It uses a Fisher–Yates shuffle, so every permutation is equally likely. It draws from the ordinary random generator rather than the cryptographic one, which is right for shuffling a list and would not be right for a lottery draw.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close