Free Line Sorter Online

Sort lines of text alphabetically, numerically, by length, or randomly shuffle them. 100% client-side — your text stays private.

Line Sorter

Input
Output
0
Total Lines
0
Non-Blank Lines
0
Unique Lines
0
Blank Lines

How do you sort lines of text? Split the text on line breaks, compare the resulting lines with a rule, and join them back together. This tool offers seven rules: A-Z and Z-A compare the lines character by character, two length modes compare how many characters each line holds, numeric compares the number at the start of each line, shuffle randomises the order, and reverse flips the input order. Blank-line removal and deduplication run before the sort.

How to Use the Line Sorter

  1. Paste one item per line — The input panel treats every line break as a record boundary. A comma-separated list will be handled as a single line, so split it first with Find & Replace.
  2. Set the options before you sortRemove blank lines and Deduplicate while sorting are applied to the input before any comparison happens, so they change what gets sorted rather than how. Case-sensitive affects A-Z, Z-A and the deduplication key only.
  3. Pick a sort mode — The seven buttons re-run immediately and stay active while you keep typing. A-Z is the mode in force before you click anything, so the output panel is already alphabetised as soon as you paste.
  4. Read the four statisticsTotal Lines and Blank Lines describe the input. Non-Blank Lines counts input lines with visible content. Unique Lines reports how many lines came out, which equals the number of distinct lines only when deduplication is on.
  5. Chain a second pass with SwapSwap moves the output back into the input. Use it to sort by length and then alphabetise within that, or to apply Reverse to an already-sorted list instead of to the original order.
  6. Copy the resultCopy writes the output panel to your clipboard and confirms with a tick for two seconds. Clear empties the input and resets the statistics without changing your option checkboxes.

How the Sorting Works

Every keystroke and every button click runs the same four-stage pipeline, about 50 ms after you stop typing. The text is split on the newline character into an array of lines; the two filtering options are applied; the array is sorted with the comparison function for the active mode; and the result is joined back together with newlines. Nothing is remembered between runs, which is why changing an option instantly reproduces the whole result from your original input rather than from the previous output.

Alphabetical order comes from comparing the two lines directly with the < and > operators after optionally folding case:

key = caseSensitive ? line : line.toLowerCase()

That comparison walks the two strings character by character and orders them by Unicode code unit, not by dictionary rules. The practical consequences are worth knowing before you trust the output: digits come before letters, all capital letters come before all lowercase ones, and accented Latin letters sort after plain z because their code points are higher. Turning Case-sensitive off sidesteps the capitals problem by lowercasing both keys before comparing, which is why it is the default state. It does not fix the accents — Zürich still lands after Zwolle, where a German or French dictionary would put it before.

The sort is stable, as JavaScript has required since ES2019, so lines whose keys compare equal keep the order they had in your input. With case-folding on, Apple and apple are equal keys and stay in the order you pasted them.

What each button actually compares

ButtonComparesUses the case optionWorth knowing
A-ZThe whole line, by Unicode code unitYesDigits before letters, accents after z
Z-AThe same comparison, invertedYesThe exact mirror of A-Z
Length (Short-Long)line.length in UTF-16 code unitsNoAn emoji counts as two, a tab as one
Length (Long-Short)The same count, descendingNoEqual-length lines keep input order
NumericThe number parsed from the start of the lineNoA line with no leading number counts as 0
Random ShuffleNothing — a Fisher-Yates shuffleNoA new order on every click
ReverseNothing — flips the input orderNoFlips your original text, not the last sort

Reverse does not undo a sort. Each run rebuilds the line list from the input panel, so Reverse always flips the order you pasted, never the order you are currently looking at. To reverse a sorted list, click Swap to push the output back into the input first, then Reverse. To flip an A-Z sort, just use Z-A.

Numeric Sorting and Its Edges

Numeric mode reads a number from the beginning of each line with JavaScript's parseFloat and sorts by that value. Leading whitespace is skipped, and parsing stops at the first character that cannot continue a number, so trailing text is simply ignored. A line that yields no number at all is treated as 0 — not moved to the front, which matters as soon as your list contains negatives, because those will sort before the text lines.

LineValue used for sortingWhy
4242A plain integer
-3.5-3.5Signs and decimals are understood
1e31000Exponent notation is understood
12 apples12Parsing stops at the space; the rest is ignored
apples 120Nothing numeric at the start, so the fallback applies
$25.000The currency symbol blocks parsing
1,2341Parsing stops at the thousands separator
3.5.23.5The second dot ends the number, so version strings misorder

Two habits avoid nearly all of this. Put the number first on the line, and strip currency symbols and thousands separators before you paste — Find & Replace handles both in one pass. For version numbers and for filenames like img2.png and img10.png, note that neither mode does natural sorting: A-Z compares 1 against 2 character by character and puts item10 before item2. Zero-padding the numbers to a fixed width, so the list reads item02 and item10, makes alphabetical order and numeric order agree.

Filtering, Deduplication and the Statistics

Remove blank lines drops any line that is empty after whitespace is trimmed from both ends, so lines holding only spaces or tabs go too. It runs first, which means blank lines never reach the sort and never appear in the output.

Deduplicate while sorting runs next, on the input order rather than on the sorted order. It walks the lines from top to bottom and keeps the first occurrence of each key, discarding later repeats — so if two lines differ only in trailing spaces or in capitalisation with case-folding on, the copy you see in the output is the one that appeared first in your text. The key respects the Case-sensitive checkbox: with it off, Berlin and BERLIN collapse into one entry; with it on, they are two.

The four tiles below the panels describe different things, and one of them has a misleading label. Total Lines and Blank Lines both count the input as pasted. Non-Blank Lines counts the input lines that contain visible characters. Unique Lines reports the number of lines in the output, which is genuinely a count of distinct lines only when deduplication is switched on — with it off, the tile simply mirrors how many lines the sort produced.

Frequently Asked Questions

By Unicode code unit, not by dictionary rules. Digits sort before letters, and accented Latin letters such as é and ü sort after plain z because their code points are higher. Capitals are the one case the tool handles for you: Case-sensitive is off by default, so both lines are lowercased before comparing. Switch it on and every capitalised line moves ahead of every lowercase one.

It reads a number from the start of each line with parseFloat and sorts by that value. Leading spaces are skipped and any text after the number is ignored, so 12 apples sorts as 12. A line with nothing numeric at the start counts as 0 rather than being moved to the front, so in a list containing negative values those text lines sit above the negatives. Currency symbols, thousands separators and second decimal points all stop the parse early.

Because alphabetical comparison works character by character, and the character 1 comes before 2. There is no natural or human sort mode here. The fix is to zero-pad the numbers so they are all the same width — item02, item10 — after which alphabetical order and numeric order are identical. Numeric mode does not help either, since it only reads a number from the start of the line.

No request is made with it, and there is no server side to this tool — the split, filter, sort and join all run in JavaScript in your tab. Be aware of one detail: the tool also mirrors your input and your option settings into the page URL so a list can be bookmarked or reloaded. That URL stays in your address bar and history, so clear the input before sharing the link if the lines contain anything confidential.

It runs before sorting, walks the lines from top to bottom, and keeps the first occurrence of each key while dropping later repeats. The key honours the Case-sensitive checkbox. One quirk is worth knowing: because the tool tracks what it has seen in a plain JavaScript object, a line consisting of exactly a built-in property name — constructor, toString, valueOf, hasOwnProperty or __proto__ — is treated as already seen and is dropped entirely. Check the output if you are deduplicating a list of property names.

Because every run rebuilds the list from the input panel. Reverse flips the order of the text you pasted, not the order currently shown in the output. If you want the reverse of an alphabetical sort, use Z-A. If you want the reverse of a length or numeric sort, click Swap first so the sorted output becomes the input, then click Reverse.

It uses a Fisher-Yates shuffle, which visits each position once and swaps it with a randomly chosen earlier position, so every ordering is equally likely given a fair source of randomness. The source is Math.random(), which is fine for picking a presentation order or randomising flashcards but is not cryptographically secure and should not be used where the outcome carries money or legal weight.

Use a spreadsheet when the data has columns and the sort key is one of them, because this tool only ever compares whole lines and has no concept of a second field. Use this when the data is a flat list — imported IDs, email addresses, tags, log lines, a set of filenames — where pasting into a sheet is more work than the sort itself. For pure duplicate removal without reordering, the Duplicate Line Remover preserves the original sequence.

Use Cases

Comparing Two Exported Lists

Sort both a database export and a vendor's spreadsheet column A-Z so the rows line up, then run them through a diff to see which records are missing instead of scanning by eye.

Cleaning an Imported Address List

Paste a column of email addresses collected from several forms, turn on blank-line removal and deduplication with case-folding off, and get one alphabetised entry per recipient before the send.

Ranking Rows That Start With a Number

Sort a pasted table of scores, prices or durations where the figure is the first thing on the line, so the top and bottom of the range are visible without opening a spreadsheet.

Finding the Outliers by Length

Sort a list of product titles or meta descriptions long-to-short to see instantly which entries will be truncated by a character limit, and short-to-long to spot the placeholder rows nobody filled in.

Randomising a Running Order

Shuffle a list of names to set the order of demos at a team meeting, draw the sequence for a tournament bracket, or reorder a question bank so a practice quiz is not the same twice.

Tidying a Config or Dependency File

Alphabetise a block of environment variables, a package list or a set of import statements so the file has one obvious insertion point and future diffs show only the line that really changed.