To sort a list alphabetically, put one item per line, run it through something that sorts by alphabet rather than by character code, and copy the result back. That is ten seconds of work. What brings people here is the second half: the sorted list arrives with every capital letter bunched at the top, or with file10 sitting above file2, or with the accented names dumped at the end. None of that is a bug. It is what "alphabetical" means to a computer until you tell it otherwise.
Why the capital letters end up first
A plain sort compares text by the numbers behind the characters. In ASCII the digits run 48 to 57, the capitals 65 to 90 and the lowercase letters 97 to 122, so every capital lands ahead of every lowercase letter and Zebra comes before apple. That is the default in JavaScript, in Python, in a database column with a binary collation, and in Unix sort under the C locale.
Alphabetical order in the human sense is a much larger piece of machinery called collation. The Unicode Collation Algorithm compares in passes — base letters first, then accents, then case — so a and A belong together and é slots next to e rather than trailing after z. Every browser ships with it, which is why a line sorter that uses your browser's collation returns the order you meant, capitals interleaved and accents in place.
When code point order is the right answer
Keep the raw comparison when the audience is a machine: checking that a config file is in the order a linter expects, reproducing a database index, or producing a list that must come out byte-identical everywhere.
That last case matters more than it sounds, because collation is genuinely locale-aware. Swedish files å, ä and ö after z; German treats them as variants of a and o; Estonian puts z between s and t. A sorter follows whatever language the machine is set to, so two colleagues in two countries can sort the same list and get two different orders. If everyone has to agree, use code point.
Why file10 comes before file2
Because alphabetical order reads digits as characters, not as quantities. It compares the 1 against the 2, decides 1 is smaller, and stops. The 0 never gets a vote. Natural order fixes this by treating each run of digits as a number, which is what anyone reading a list of filenames, chapters or invoice numbers expects.
It is not a universal repair. Version strings and decimals want opposite things: under natural rules 1.10 is one point ten, correct for a release number and wrong for a measurement where 1.10 equals 1.1. Dates written as 3/4/2025 sort on whichever number is printed first and never on the actual date — rewrite them as 2025-04-03 and plain alphabetical order becomes correct chronological order for free. And 007 compares equal to 7 under natural rules, so which one lands first comes down to which one you typed first.
What if the lines are numbers, not words?
Then you want a numeric sort, which pulls the number out of each line and orders by its value, wherever in the line it sits — 12 Acacia Avenue included.
The catch is that a line can hold more than one number and the sorter has to pick. Taking the first is usually right — Invoice 204 of 900 sorts on the 204 — and occasionally wrong, as in Route 66 revisited in 1998. Lines with no number at all have no position on a number line; a sensible tool parks them at the end rather than pretending they are zero.
How to sort in the software you already have
A spreadsheet
Select the whole table, never a single column, then use Data and Sort. Sorting one column while the others stay put is the classic way to shred a dataset, and Excel's prompt asking whether to expand the selection is all that stands between you and a sheet where every row belongs to the wrong person. Excel ignores case unless you switch it on under Sort Options, orders numbers before text when ascending, and parks blank cells at the bottom in either direction.
Word and code editors
Word sorts paragraphs: Home, then the A-Z Sort button, then Ascending. VS Code has "Sort Lines Ascending" in the command palette, with no shortcut bound by default, and most editors have an equivalent. Both are fine for a short list, and neither tells you what it did — no counts, no warning that four lines were identical.
The command line
sort list.txt uses your locale, so it behaves roughly like collation; LC_ALL=C sort list.txt drops to byte order. Add -f to ignore case, -n for numbers, -V for version strings and -u to drop duplicates on the way past. Those flags are GNU coreutils; macOS ships the BSD version, where the selection differs. One surprise worth knowing: in a UTF-8 locale GNU sort largely ignores punctuation and spaces when comparing, so de Luca and DeLuca end up side by side. Helpful for names, baffling for everything else.
Clean the list before you sort it
Sorting is an excellent way to discover everything wrong with your data: it drags the broken entries into one visible clump.
- Leading spaces. A space is character 32, below every letter, so
Parissorts above the entire alphabet. Trim first. - Invisible characters. A non-breaking space or a zero-width joiner pasted in from a web page looks like nothing and sorts like something. If a line insists on going to the wrong place, the characters you cannot see are the usual culprit.
- Two spellings of the same accent. An é can be one character or an e followed by a combining mark, and the two are different strings. Collation reconciles them; code point order does not. This is the same mismatch behind why one visible character is not always one unit of text.
- Duplicates. Sorting puts them next to each other, which is the point at which most people notice them. You can strip the repeats in the same pass, or read up on how deduplicating a list actually behaves before you throw anything away.
- A header row. If the first line is a column title, pin it in place or it gets sorted into the middle of the data.
The sorter on this site does all of that in one pass and reports the counts — lines in, lines out, blanks dropped, duplicates removed — which is how you notice that a list of 340 items was really 312.
What a line sorter cannot do for you
It sorts whole lines, which means it sorts by whatever sits at the start of the line. A list of names written as Ada Lovelace sorts by first name, and no setting changes that. To sort by surname you have to rewrite the lines with the surname first, or move to a spreadsheet and build a helper column.
Conventions are your problem too. Libraries file The Beatles under B, ignoring the leading article, and whether van der Berg goes under V or B depends on the country. Those are editorial decisions, not settings: fix the text, then sort.
Two structural limits. A CSV with a newline inside a quoted field gets split in the wrong place, because a line-based tool cannot tell the quote is still open. And an indented outline is destroyed outright, since a child line has no memory of which parent it sat under.
Sorting on two keys looks impossible and is not: sort by the less important key first, then by the more important one. Stable sorts keep equal items in the order they arrived — JavaScript has guaranteed this since ES2019, GNU sort does it with -s — so the first ordering survives inside the second, and a staff list sorted by name and then by department comes out grouped by department with each group alphabetised.
Finally, size. A few hundred thousand lines sort instantly in a browser tab; a few million will freeze the page, because it runs on the same thread that draws the interface. At that scale the command line is the honest answer.
The line sorter here covers the whole routine in one pass — alphabetical or natural order, case on or off, blanks and duplicates dropped, a header row pinned — and the list never leaves your browser, which matters when the list is customer names.
If what you are really doing is sorting two copies of a list to work out what changed between them, sorting is the wrong instrument. Comparing two versions of a text tells you exactly which entries were added and which disappeared, instead of leaving you to eyeball two sorted columns side by side.
Frequently asked questions
How do I sort a list alphabetically?
Put one item per line and run it through a tool that sorts by alphabet rather than by character code. In a spreadsheet, select the entire table and use Data then Sort, never a single column on its own. In a terminal, the sort command does it, following whatever language your system is set to.
Why are all the uppercase words at the top of my sorted list?
The sort is comparing character codes, where every capital letter has a lower value than every lowercase letter. Switch the tool to locale or alphabetical comparison, or turn off case sensitivity. Programming languages and databases with binary collations do this by default.
How do I make file2 come before file10?
Use natural sorting, which reads a run of digits as a number instead of as separate characters. Plain alphabetical order compares the 1 in 10 against the 2, decides 1 is smaller and stops there. Natural order is also what you want for chapters, invoice numbers and anything else counted.
How do I sort a list of names by last name?
A line sorter cannot do it, because it can only sort by what comes first on each line. Either rewrite the entries as "Lovelace, Ada" before sorting, or paste the list into a spreadsheet, split the names into two columns and sort on the second.
Does sorting a list twice undo the first sort?
No, as long as the sort is stable, and modern ones are. Equal items keep the order they arrived in, so sorting by department after sorting by name gives you departments in order with alphabetised names inside each. Sort by the less important key first.
Will two people sorting the same list get the same order?
Not always. Locale-aware sorting follows each machine language setting, and languages disagree: Swedish files a-ring and o-umlaut after z, while German sorts them with a and o. If the result has to match everywhere, use code point order instead.
Last updated September 19, 2026