Text Tools

Sort Text Lines Alphabetically

September 6, 2026

Written by Mohammad Sohail

Sorting lines alphabetically is a deceptively common task. Organizing a list of names, sorting inventory items, arranging command-line output, ordering database entries — these all require line sorting. Doing it manually in a text editor is tedious and error-prone.

When Line Sorting Is Useful

Alphabetizing a list of contacts or customers. Sorting filenames for batch processing. Organizing command-line output (like ls -la or netstat). Arranging inventory items, SKUs, or product names. Sorting IP addresses or log entries. Reversing the order of lines in a file.

What I Tested

I used the Sort Lines with several text inputs.

Input: 'banana\napple\ncherry\ndate'. Sorted A-Z: 'apple\nbanana\ncherry\ndate'. Correct alphabetical order.

Input: 'banana\napple\ncherry\ndate'. Sorted Z-A (reverse): 'date\ncherry\nbanana\napple'. Correct reverse order.

Input: 'Charlie\nalice\nBob\nDiana'. Sorted A-Z: 'alice\nBob\nCharlie\nDiana'. Correct — uppercase letters sort before lowercase in ASCII order.

Input: '3. Apple\n1. Banana\n2. Cherry'. Sorted A-Z: '1. Banana\n2. Cherry\n3. Apple'. Correct — sorted by the full line including numbers.

Step-by-Step

(1) Open the Sort Lines. (2) Paste your text with one item per line. (3) Click 'Sort A-Z' for ascending order or 'Sort Z-A' for reverse order. (4) Copy the sorted result.

Limitation

The sort is case-sensitive by default. 'apple' comes before 'Banana' because lowercase letters have higher ASCII values than uppercase. If you need case-insensitive sorting, convert all text to lowercase first using the Case Converter, then sort.

Common Mistake

Sorting numbered lists without considering numeric order. '10. Item' sorts before '2. Item' because '1' < '2' in ASCII. The tool sorts by character, not by numeric value. For numeric sorting, pad numbers with leading zeros (01, 02, ..., 10) before sorting.

How It Compares

Notepad++ can sort lines via Edit → Line Operations but requires installation and the option is buried in menus. Text editors like Sublime Text have sort commands but require a license. Our tool sorts with one click in your browser, supports both A-Z and Z-A, and has no installation required.

Privacy: Sorting happens line by line inside your browser. The list you paste is handled in memory only and disappears as soon as you close the tab.

Next Step: After sorting, if you have duplicate lines, use the Remove Duplicate Lines tool to clean them up.

Why Case Changes the Order

Every character has a numeric code, and in ASCII the codes for A to Z run from 65 to 90 while a to z run from 97 to 122. Because 65 is smaller than 97, the tool puts every capital letter before every lowercase one: Banana sorts ahead of apple, and Zebra sorts ahead of banana. The same rule applies to digits (48 to 57, so they come first), spaces, and then symbols. Accented characters such as é sit above z in most encodings, so they land at the end of the list.

If you want an order that ignores capitals, convert the whole list to lowercase with the Case Converter before sorting. To restore capitalisation afterwards, use Title Case or Sentence case on the same tool — the sort order is already correct by then.

Cleaning a Messy List Before Sorting

A list scraped from a document, spreadsheet or log file almost always arrives with invisible problems: a leading space on some lines, trailing periods, Windows carriage returns, tab characters, and blank lines left at the end. Those characters participate in the comparison, so a line with a stray leading space sorts to the very top even when its text should be in the middle, and blank lines sort above everything else.

Clean in this order: remove empty lines first, then trim spaces at both ends of each line, then remove duplicate lines so identical entries do not sit side by side, and finally sort. Four passes in the browser take under a minute and produce a list you can paste into Excel, a database import or a config file without repair work.

Sorting Lists That Came from Spreadsheets

Lists copied out of spreadsheets carry invisible characters with them: tab characters standing in for column breaks, carriage returns from Windows exports, and non-breaking spaces pasted from a web page. Those characters take part in the comparison, so a line prefixed by a tab lands above every unindented line no matter what its text says.

Strip the invisible characters before sorting, not after: paste the list, trim leading and trailing whitespace from every line, delete the blank rows the spreadsheet export added at the end, then sort. Sorting first and cleaning afterwards throws away the order that was just computed, and both steps end up running twice.

Frequently Asked Questions

Does sorting lines remove duplicates?

No. Sorting only reorders the lines you already have — every repeated line is kept and moved next to its twin. To drop repeats afterwards, paste the sorted result into the Remove Duplicate Lines tool, which keeps the first occurrence of each identical line.

Why did my list sort in the wrong order?

Usually leading spaces, blank lines or capital letters. A line that starts with a space sorts before everything else, a blank line sorts first, and uppercase letters have lower ASCII values than lowercase, so Banana comes before apple. Trim the lines and convert to one case before sorting if the order still looks wrong.

Can it sort numbers correctly?

It sorts numbers as text, so 10 comes before 2 because 1 is smaller than 2. For true numeric order, pad every number to the same width first — 01, 02 and 10 — or sort them in a spreadsheet instead.

How do I sort while ignoring punctuation or accents?

Strip what you do not want to compare first: convert the text to lowercase with the Case Converter, remove leading numbering, and paste again. The tool compares whole lines character by character, so any symbol you leave in will influence the result.

Is my list sent to a server when I sort it?

No. Sorting happens entirely in your browser tab. The text stays in memory, is never uploaded, and disappears as soon as you close or refresh the page.

Try it yourself

Open Tool →