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:
- Go to TextWonder's Sort Lines tool.
- Paste your text (any number of lines).
- Choose: A→Z, Z→A, numeric, or random.
- 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.
Method 2: Excel or Google Sheets
If your data is already in a spreadsheet:
Excel:
- Select the column containing your lines.
- Go to Data → Sort.
- Choose ascending (A–Z) or descending (Z–A).
- If you have other columns, choose whether to expand the selection (sort entire rows) or sort the column only.
Google Sheets:
- Select the column.
- Right-click → Sort sheet A→Z (or Z→A).
- 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:
- Notepad++: Select all → Edit → Line Operations → Sort Lines Lexicographically Ascending/Descending
- Sublime Text:
F9to sort selected lines (requires selecting all first) - VS Code: No built-in sort. Install the "Sort Lines" extension or use the terminal.
- Vim:
:sortto sort all lines,:sort!to sort in reverse
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:
- Alphabetical: 1, 10, 100, 2, 20, 3
- Numeric: 1, 2, 3, 10, 20, 100
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.