OnlineTextLab
Esc

Sort Lines

Alphabetical sorting puts file10 before file2.

Sort by
Direction

Ctrl or Cmd + Enter copies the result.

Runs on your device. Your files and text are not uploaded.

About Sort Lines

Pasting a list and pressing sort sounds trivial until the list contains numbers. A plain alphabetical sort compares one character at a time, so track-10 lands before track-2, and $1,200 lands before $85. Those results are technically correct, and not what anyone wanted. Choose Natural and the numbers inside the text are compared as numbers. Choose Numeric and the whole list orders by the value of the first number on each line.

There are six ways to sort: Alphabetical, Natural, Numeric, Length, Reverse order and Shuffle. Results update as you type or switch, so it takes one click to compare two orders. Blank lines are removed by default, because a stray one would otherwise jump to the top.

Accented letters sort beside their base letters, so Éclair sits with the E words and not after Z, as it would in a simple sort by character code.

How it works

Alphabetical and Natural use the browser's locale-aware collator (Intl.Collator), the same language-sensitive comparison used in file managers, with its numeric option switched on for Natural. It orders according to your browser's language. With Ignore case on, A and a count as equal, and lines that compare as equal stay in their original relative order.

Numeric finds the first number in each line and sorts on its value. It understands a minus sign, decimals and thousands commas, and looks past text in front, so $1,200 rent sorts as 1200 and €3.50 as 3.5. A hyphen joined to a word is not read as a minus sign, so item-3 is 3. Lines with no number go to the end in both directions, and ties are settled by natural order.

Length counts characters the way you see them, so an emoji counts as one. Reverse order flips the list without comparing anything. Shuffle uses the Fisher-Yates method, which gives every order an equal chance, and Shuffle again produces a new one. It relies on the browser's general random number source, so it suits raffles among friends and not anything with money or legal weight attached.

How to use Sort Lines

  1. Paste your list into the Lines to sort box, one item per line, or press Upload. Try an example gives you a list that shows why the sort method matters.
  2. Choose a method under Sort by.
  3. Pick a Direction. The labels change with the method, for example Low to high for Numeric.
  4. Adjust Ignore case, Remove blank lines, Remove duplicates and Trim spaces if you need to.
  5. Copy the sorted list with Copy, or Ctrl or Cmd + Enter. Download saves it as sorted-lines.txt.

Why the method matters

Input
track-10.mp3
track-2.mp3
track-1.mp3

(and, separately)
$1,200 rent
$85 phone
$12.50 lunch
no price yet
Output
Alphabetical: track-1, track-10, track-2
Natural: track-1, track-2, track-10

Numeric, High to low:
$1,200 rent
$85 phone
$12.50 lunch
no price yet

The file names need Natural because the number sits inside the text. The price list needs Numeric, which reads past the dollar sign and the thousands comma, and it puts the line with no number last.

When it helps

  • Ordering numbered files or chapter names so 10 follows 9.
  • Ranking lines from a report by the value at the start, such as 1,204 visits /pricing.
  • Alphabetizing a bibliography, a glossary or a guest list.
  • Picking a random order for presentations by shuffling the list of names.
  • Finding the shortest and longest entries in a list by sorting on Length.

Tips for a better result

  • Lines are compared from the start, so Dr. Adams sorts under D. If the sort key sits later in the line, move it to the front first with Find and Replace in Regex mode.
  • Numeric sorts on the first number, so a date at the start of a line takes priority over a price later on it.
  • ISO dates such as 2026-03-14 sort correctly with plain Alphabetical. Dates such as 3/14/2026 do not, so rewrite them first.
  • Turn on Trim spaces if a list pasted from a document sorts oddly, as an indented line would otherwise go first.

Good to know

  • It sorts whole lines, with no way to choose a column. For a CSV or table with a sort column, use a spreadsheet.
  • Numeric reads European formats such as 1.200,50 differently from what you intend, taking 1.2 as the number.
  • It does not understand dates, month names or roman numerals as values.
  • Alphabetical order follows your browser's language, so the same list can sort slightly differently on a device set to Swedish or German.

Questions people ask

What is natural sort?

It treats a run of digits as a single number, so file2 comes before file10, the way a person would order them. A plain alphabetical sort compares the 1 in 10 against the 2 and puts file10 first.

What is the difference between Natural and Numeric?

Natural compares the text and treats any digits within it as numbers, which suits names with numbers in them. Numeric ignores the text and orders only by the first number on each line, which suits a ranking or a list of prices.

Why does a capital letter sort differently from a lowercase one?

With Ignore case off, the two are treated as different, and the collator puts a before A. With it on, they count as equal and keep their original order. Most people want it on, which is the default.

Is the Shuffle truly random?

Every order is equally likely in terms of the method, but the numbers come from the browser's general random generator and not a cryptographic one. That is fine for casual use, not for a prize draw with legal rules.

What to use next

Last reviewed . Read our editorial policy.