Skip to content

Sort Lines Alphabetically, Numerically or by Length

Paste a list, one item per line, and get it back in alphabetical, numeric or length order, with duplicates removed if you want.

Runs in your browserFree, no sign-upLast reviewed

Settings

Results update automatically as you type.

Sorted lines (7)

apple apple banana banana cherry date elderberry

Quick answers

How do I sort lines alphabetically?
Paste the list with one item per line and leave Sort by on Alphabetical (A → Z). The sample list banana, apple, cherry, apple, date, banana, elderberry comes back as apple, apple, banana, banana, cherry, date, elderberry.
How do I put a list in alphabetical order and remove duplicates?
Choose an alphabetical order and tick Remove duplicates. Repeated lines are reduced to one copy before sorting, so the 7-line sample list becomes 5 lines: apple, banana, cherry, date, elderberry.
Why does 10 come before 2 when I sort a list?
Plain text sorting compares character by character, and the character 1 is lower than 2. This tool's alphabetical modes use natural order, which reads runs of digits as numbers, so item1, item2, item3, item10, item20 come out in counting order.
Is alphabetical sorting here case sensitive?
No. Capital and lowercase letters are treated as the same letter, so Apple and apple sort together instead of all capitals coming first. Lines that differ only by case keep the order they had in your list.
How do I sort a list of numbers from smallest to largest?
Choose Numeric (0 → 9). Each line is read as a number, so decimals and negatives are placed correctly: 10, 9, 100, 1.5, -3, 25 becomes -3, 1.5, 9, 10, 25, 100. Choose Numeric (9 → 0) for largest first.
How do I reverse the order of lines without sorting them?
Choose Reverse current order. The last line becomes the first and nothing else changes, which is useful for flipping a log or a ranked list.

Why use Sort Lines

Paste a list with one item on each line and pick an order from the Sort by menu: Alphabetical A to Z or Z to A, Numeric low to high or high to low, Length short to long or long to short, or Reverse current order. Alphabetical sorting ignores capital letters and accents and reads numbers inside text as numbers, so item2 comes before item10 and Apple sits beside apple. Tick Remove duplicates to keep one copy of each repeated line. Every line is trimmed of spaces at both ends and blank lines are dropped before sorting. The result shows how many lines came out and can be copied or downloaded as sorted.txt.

The seven sort orders compared

Input, in this order: banana, apple, cherry, apple, date, banana, elderberry. The two numeric rows use a list of numbers instead.

Sort byResult
Alphabetical (A → Z)apple, apple, banana, banana, cherry, date, elderberry
Alphabetical (Z → A)elderberry, date, cherry, banana, banana, apple, apple
Length (short → long)date, apple, apple, banana, cherry, banana, elderberry
Length (long → short)elderberry, banana, cherry, banana, apple, apple, date
Reverse current orderelderberry, banana, date, apple, cherry, apple, banana
Alphabetical (A → Z) with Remove duplicatesapple, banana, cherry, date, elderberry
Numeric (0 → 9) on 10, 9, 100, 1.5, -3, 25-3, 1.5, 9, 10, 25, 100
Numeric (9 → 0) on 10, 9, 100, 1.5, -3, 25100, 25, 10, 9, 1.5, -3

In the length orders, lines of equal length stay in the order you pasted them, which is why banana, cherry, banana are not regrouped.

How alphabetical order handles numbers, capitals, accents and symbols

Each row shows the real A to Z result for a small list.

List pastedSorted A to ZWhat it shows
item10, item2, item1, item20, item3item1, item2, item3, item10, item20Digits inside text are compared as numbers
v1.10.0, v1.2.0, v1.9.3, v2.0.0v1.2.0, v1.9.3, v1.10.0, v2.0.0Version numbers come out in release order
12 Main St, 9 Oak Ave, 101 Pine Rd9 Oak Ave, 12 Main St, 101 Pine RdLeading numbers sort by value
banana, Apple, cherry, apple, BananaApple, apple, banana, Banana, cherryCase is ignored; ties keep pasted order
zebra, Éclair, eclair, Ångström, apple, ölÅngström, apple, Éclair, eclair, öl, zebraAccented letters sort with their base letter
Chapter 2, Chapter 10, Appendix, _notes, #tag, 42_notes, #tag, 42, Appendix, Chapter 2, Chapter 10Symbols first, then numbers, then letters
the cat, The Beatles, a dog, An owla dog, An owl, The Beatles, the catLeading A, An and The are not skipped
2026-03-01, 2025-12-31, 2026-01-152025-12-31, 2026-01-15, 2026-03-01Year-first dates sort chronologically
03/01/2026, 12/31/2025, 01/15/202601/15/2026, 03/01/2026, 12/31/2025Month-first dates do not: the year is compared last

Numeric sorting: what works and what does not

Numeric modes read each whole line as a number. A line that is not purely a number is treated as zero.

Plain numbers with decimals and a negative

10 / 9 / 100 / 1.5 / -3 / 25, Numeric (0 → 9)

-3 / 1.5 / 9 / 10 / 25 / 100

A column with a header, a currency sign and a thousands comma

$40 / 1,200 / 15 / Total / 7, Numeric (0 → 9)

$40 / 1,200 / Total / 7 / 15

$40, 1,200 and Total cannot be read as numbers, so they count as 0 and collect at the low end in their pasted order. Remove symbols and separators first.

Lines that start with a number but contain words

3 apples / 10 pears / 2 kiwis, Numeric (0 → 9)

3 apples / 10 pears / 2 kiwis (unchanged)

Use Alphabetical (A → Z) for this kind of list. It gives 2 kiwis / 3 apples / 10 pears.

Decimals written without a leading zero

0.5 / .25 / 1e2 / -0.75 / 3, Numeric (0 → 9)

-0.75 / .25 / 0.5 / 3 / 1e2

Scientific notation is understood, so 1e2 is placed as 100.

Things to know before you paste

  • One item per line. A comma-separated list on a single line is one line and will not be split.
  • Blank lines are removed and spaces at the start and end of each line are stripped, in every mode including Reverse current order.
  • Remove duplicates is an exact match after trimming, and it is case sensitive: apple, Apple and APPLE are kept as three lines. The first copy of a repeated line is the one that stays.
  • Duplicates are removed before sorting or reversing.
  • Length is counted in characters, spaces and punctuation included. Most emoji count as 2.
  • Lines are compared from their first character. To sort by a surname or a second column, that part needs to come first on the line.
  • The alphabetical modes follow English ordering rules. Languages with their own alphabetical conventions, such as Swedish, may expect a different position for some letters.
  • There is no random shuffle option.

Sorting lines in Excel, Word, VS Code and the command line

If the list already lives in another program, you may not need to paste it anywhere.

In Excel or Google Sheets, select the column and use Sort A to Z on the Data tab or menu. In Word, select the lines and use the Sort button on the Home tab, which sorts paragraphs as text, numbers or dates.

In VS Code, select the lines, open the Command Palette and run Sort Lines Ascending or Sort Lines Descending. On macOS and Linux, sort file.txt sorts alphabetically, sort -n numerically, sort -r in reverse, sort -u drops duplicates and sort -V handles version numbers.

The difference is in the defaults. Some of these sort by raw character codes unless told otherwise, which puts every capital letter ahead of every lowercase one, and most put item10 ahead of item2. This page applies case-insensitive natural order without any flags.

Step by step

  1. 1

    Paste your list into Lines with one item per line.

  2. 2

    Choose an order under Sort by. Alphabetical (A → Z) is the default.

  3. 3

    Tick Remove duplicates if each entry should appear only once.

  4. 4

    Read the Sorted lines panel. The number in its heading is the line count after blanks and duplicates are removed.

  5. 5

    Copy the result or download it as sorted.txt.

Frequently asked questions

Can it sort names by last name?
Only if the last name comes first on each line, as in Smith, John. The sort always starts from the first character of the line. Adams, Zoe / de Vries, Anna / McDonald, Lee / O'Brien, Pat / Smith, John is the result for a list written that way.
Can I sort a comma-separated list?
Not directly. Put each item on its own line first, for example by replacing every comma with a line break in a text editor. After sorting you can join the lines back together the same way.
What is natural sort order?
It is alphabetical order that treats a run of digits as one number instead of separate characters. Chapter 2 comes before Chapter 10, and file9 before file10. Plain character-by-character sorting would put the 10s first.
When should I use Numeric instead of Alphabetical?
Use Numeric when every line is just a number and the list includes negatives, since it orders them by value. For labels that contain numbers, such as item10 or 12 Main St, use Alphabetical, which already reads the digits as numbers.
How do I find the longest or shortest line in a list?
Choose Length (long → short) to bring the longest line to the top, or Length (short → long) for the shortest. It is a quick way to spot entries that will overflow a column or a character limit.
Does sorting change the text of my lines?
Only the edges. Spaces and tabs at the start and end of each line are removed and blank lines are dropped. The characters inside each line, including capitals and inner spacing, are left as they were.
Does Z to A simply flip the A to Z result?
Almost. The order of different entries is flipped, but lines that are equal apart from case keep their pasted order in both directions. For an exact mirror image, sort A to Z, paste the result back and choose Reverse current order.
Is my list uploaded to a server?
No. Sorting is done in your browser, so customer names, email lists and other private data stay on your device.

Looking for something else? Browse all text tools or see every tool.