✍️ TextWonder 📄 PDFWonder 📁 DocWonder 🖼️ ImageWonder 🛠️ DevWonder 🎓 StudentWonder 🧮 CalcWonder 🩺 HealthWonder 🎨 ColorWonder 💾 DataWonder 📐 UnitWonder
TextWonder
Text Formatting · 4 min read ·

How to Sort Lines of Text Alphabetically: 4 Methods

Learn how to sort lines of text alphabetically, numerically, or randomly using free online tools, Excel, Google Sheets, and the command line.

Sorting lines of text is a surprisingly common task: alphabetising bibliography entries, sorting keyword lists for SEO, organising product names, sorting log entries, or just cleaning up a list. Here are four reliable methods.

Method 1: Free Online Tool (Instant)

The fastest option for any one-off sorting task:

  1. Go to TextWonder's Sort Lines tool.
  2. Paste your text (any number of lines).
  3. Choose: A→Z, Z→A, numeric, or random.
  4. Copy the sorted output.

The tool preserves blank lines, handles case-insensitive matching, and works instantly in your browser with no data leaving your device.

Free Tool
Sort Lines →
Sort any list of lines alphabetically, reverse, numerically, or randomly. Free, instant, browser-based.

Method 2: Excel or Google Sheets

If your data is already in a spreadsheet:

Excel:

  1. Select the column containing your lines.
  2. Go to Data → Sort.
  3. Choose ascending (A–Z) or descending (Z–A).
  4. If you have other columns, choose whether to expand the selection (sort entire rows) or sort the column only.

Google Sheets:

  1. Select the column.
  2. Right-click → Sort sheet A→Z (or Z→A).
  3. Alternatively: Data → Sort range for more options.

Method 3: Command Line

For large files (thousands or millions of lines), the command line is the most efficient:

Linux / macOS:

sort input.txt > sorted.txt — alphabetical ascending

sort -r input.txt > sorted.txt — reverse alphabetical

sort -n input.txt > sorted.txt — numeric sort

sort -u input.txt > sorted.txt — sort and remove duplicates simultaneously

Windows PowerShell:

Get-Content input.txt | Sort-Object | Set-Content sorted.txt

Get-Content input.txt | Sort-Object -Descending | Set-Content sorted.txt

Method 4: Text Editors

Some text editors have built-in sort functionality:

Alphabetical vs Numeric Sorting: An Important Difference

Alphabetical (lexicographic) sorting compares character by character. This means 10 comes before 9 alphabetically (because "1" < "9"), which is unintuitive when sorting numbers.

For lists containing numbers, always use numeric sort:

TextWonder's Sort Lines tool offers both options. The command-line sort -n flag enables numeric sorting.

Frequently Asked Questions

How do I sort lines of text alphabetically online?

Paste your text into TextWonder's Sort Lines tool and it instantly sorts all lines alphabetically (A–Z). You can also sort in reverse (Z–A), numerically, or randomly. Free, no signup.

Can I sort lines numerically?

Yes. TextWonder's Sort Lines tool offers numeric sorting, which sorts numbers by value (1, 2, 10, 100) rather than lexicographically (1, 10, 100, 2).

How do I sort lines in Excel?

In Excel, select your column and use Data → Sort. Choose ascending (A–Z) or descending (Z–A). For a single column of text items, select it and sort directly without affecting other columns.

How do I sort lines in Notepad++ or VS Code?

Notepad++: Select all text, then Edit → Line Operations → Sort Lines Lexicographically Ascending. VS Code: There's no built-in sort, but the "Sort Lines" extension adds it, or use the command palette with a terminal sort command.

What is lexicographic sorting vs natural sorting?

Lexicographic (alphabetical) sorting compares characters one by one: "10" comes before "9" because "1" < "9". Natural sorting understands numbers: "9" comes before "10". For numbered lists, natural sorting gives more intuitive results.