b2KIT

Sort Lines Tool

Sort lines alphabetically, numerically, by length, or in reverse order.

How to Use Sort Lines Tool

  1. 1

    Paste your text

    Enter the lines of text you want to sort.

  2. 2

    Choose sort order

    Select alphabetical, reverse, numeric, or random order.

  3. 3

    Copy sorted text

    Click copy to grab the sorted lines output.

Tested tool guide Text and writing tools Checked August 16, 2026

What Sort Lines Tool does, with a checked example

Paste a block of lines into this tool and it reorders them in one of four ways: alphabetical, numerical, by length, or reverse order. The block comes back in the new order, ready to copy out. The thing that trips most people up is that alphabetical sorting works on characters, not values: the string '10' sorts before the string '2', because the digit '1' precedes the digit '2' in the character table. When your lines look like numbers, choose the numerical mode, or the ordering will look broken even though the tool did exactly what it was asked.

Worked example

A concrete input and expected output from the current implementation.

Input

10
9
8
2
1

Expected output

1
2
8
9
10

In numerical mode each line is compared as the value it represents, so 2, 8, and 9 come before 10. The same input in alphabetical mode would return 1, 10, 2, 8, 9, because strings are compared character by character and the digit '1' is smaller than '2', '8', and '9'.

How the result is produced

1

The sort key per mode

Each mode orders lines by a different key: the characters of the line (alphabetical), the number the line parses to (numerical), or the character count (by length). Lines come back in ascending order of that key, and reverse order flips the result instead of computing a new one. Because the key is computed per line, sorting never merges, splits, or rewrites lines; it only changes their order.

2

Alphabetical comparison

Alphabetical comparison walks two lines character by character from the left, and the first position where they differ decides the order. A line that is a prefix of another, like '10' next to '10A', comes first. Digits, punctuation, and spaces take part in the comparison like any other character, so the result reflects exact text, not the way a dictionary would alphabetize the words.

Good uses

  • Put a list that is expected to be in alphabetical order back into order: names, URLs, keywords, or bookmarks that drifted out of sequence through editing. Paste, sort, copy the result.
  • Bring numbered records into true value order with the numerical mode, such as log entries, ticket IDs, or version numbers, where 2 must come before 10.
  • Find the shortest and longest entries in a list, like file names or list items, by sorting by length and reading the first and last lines of the result.

Limits and checks

  • Whitespace is part of the key. A blank line is the empty string, which sorts first alphabetically and counts as the shortest line, and trailing spaces can push a line ahead of an identical-looking clean one. If pasted data has padding, check whether the tool trims it before trusting the order.
  • Duplicates are kept. Sorting preserves every occurrence, so one hundred copies of the same line still number one hundred after sorting. Producing a deduplicated list is a separate step that this tool does not take.
  • Numerical mode needs numbers. Lines that are not cleanly numeric, such as 'n/a' or 'v2.1.3', may land in unexpected places. Sort a small sample containing your oddest lines first, and check the result before running a large file through it.

Common questions

Will sorting change the text of my lines?

No. The tool reorders whole lines and does not rewrite their contents, so case, punctuation, and spacing inside a line come back exactly as entered. That is why alphabetical mode can place '10' ahead of '2': the tool sorts the exact text instead of interpreting it. If you see a surprising order, the mode is the thing to change, not the input.

Does the tool remove duplicate lines?

No. Every occurrence is preserved, so duplicates stay duplicates after sorting. To get each line once, deduplicate first and then sort, or sort first: equal lines end up adjacent, which makes repeats easy to spot and delete by hand.

References and verification

The example and behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools