You have a list of names, a class register, a wedding guest list, a team roster, and you need it in surname order. You paste it into a sorter, choose A to Z, and get back a list that is perfectly alphabetical and completely wrong: ordered by first name. Nothing malfunctioned. The list was written first name first, and a sorter can only order what a line starts with.
This guide explains the honest workflow for sorting names by surname with the free Sort Lines Tool on Ovatly. There is no surname setting to switch on. The fix is a short preparation step: put the surname at the front of each line, then let the sorter do the part it is good at. For a few dozen names the preparation takes minutes.
Contents
- Quick answer
- Why the sorter orders by first name
- The preparation: surname first on every line
- Flipping names by hand and with find and replace
- How to sort by surname, step by step
- Worked example: four names, before and after
- Edge cases: middle names, particles and double surnames
- Limitations and alternatives
- Common mistakes
- FAQs
- Conclusion
Quick answer
Rewrite each line so the surname comes first, in the form "Surname, First name": "Priya Sharma" becomes "Sharma, Priya". Then paste the list into the Sort Lines Tool, choose A to Z, and copy the result. The comparison ignores case, so lowercase lines still file with their letter group, and sorting changes only the order of the lines, never their text. If the finished list must be displayed first name first, flip the names back after sorting, keeping the new order.
Why the sorter orders by first name
The tool compares lines from their first character onwards. It offers seven modes: A to Z, Z to A, numeric low to high, numeric high to low, shortest first, longest first, and reverse order. None of them looks inside a line for a surname, because a line of text does not label which word is which. In "Maria Alvarez", nothing in the characters themselves says Alvarez is the family name; in another list the family name could come first already, or the line could be a company name.
So the alphabetical modes do the only well-defined thing available: order by the start of the line. That is a feature when the lines already begin with the thing you are ordering by, as entries in a bibliography do. With first-name-first names, the preparation step exists to make the start of each line be the surname. Once the surname starts each line, the sorter's simple rule and your goal match.
The preparation: surname first on every line
The target form is one name per line, surname first, followed by a comma, then the given names: "Okafor, Daniel". The comma is worth using even though the sorter does not need it. It makes the structure visible, it matches the convention used in indexes and reference lists, and it makes flipping the names back afterwards a recognisable pattern.
Be consistent. If some lines end up as "Sharma, Priya" and others as "Tom Becker", the missed line files under T, and the error looks like a sorting bug when it is a preparation gap. A quick scan down the left edge of the prepared list catches this before you sort.
Flipping names by hand and with find and replace
For a short list, flipping by hand is fastest and safest: read the name, retype or cut and paste the surname to the front, add the comma. Twenty names take minutes, and you catch the awkward ones as you go.
For a long list where every line follows one regular pattern, exactly "First Last" with a single space and no middle names, find and replace can do the mechanical part: the related Find and Replace tool here works on pasted text, and a careful pass can restructure regular lines in bulk. Treat this as an option for genuinely uniform lists only. The moment a list mixes patterns, middle names, initials, two-word surnames, a bulk pass will quietly mangle the irregular ones, and the damage is harder to spot than the original problem. A practical compromise for a mixed list: flip the regular names in bulk, then hand-check every line against the original before sorting.
How to sort by surname, step by step
- Prepare the list: one name per line, every line flipped to "Surname, First name" form, duplicates already removed.
- Open the Sort Lines Tool and paste the prepared list into the box.
- Choose the A to Z sort mode.
- Read the sorted result below the box. Scan the left edge: surnames should run in clean alphabetical order.
- Copy or download the sorted lines. Leave them surname-first, or flip each name back to display form if the final use requires it.
Worked example: four names, before and after
Start with the list as it was written:
Priya Sharma
Daniel Okafor
Maria Alvarez
Tom Becker
Sorted as it stands, A to Z would give Daniel, Maria, Priya, Tom: first-name order, not an alphabetical register. After preparation, the list reads:
Sharma, Priya
Okafor, Daniel
Alvarez, Maria
Becker, Tom
Now the A to Z sort produces:
Alvarez, Maria
Becker, Tom
Okafor, Daniel
Sharma, Priya
That is surname order, achieved without the tool knowing anything about names. The sort itself took a second; the few minutes went on the flipping. The sort also did not tidy names, fix spellings or merge a person listed twice. The lines came out with their text untouched, in a new order.
Edge cases: middle names, particles and double surnames
Real name lists contain names that do not fit "First Last", and each kind needs a decision from you, not from the tool:
- Middle names. "Anna Maria Silva" might have the surname Silva, with Anna Maria as given names, giving "Silva, Anna Maria". The sorter only sees the finished line, so your decision is the whole job.
- Particles. Names like "Ludwig van Beethoven" are filed under B in most English-language conventions and under V in some others. Put whichever element you file by at the front of the line.
- Double surnames. Where a person has two family names, the line should start with the first of them, in the order the person uses.
- Titles and suffixes. "Dr" at the start of a line files the name under D. Move titles out of the front of the line, or off it, before sorting.
- Single names and organisations. A line with one word sorts by that word, which is usually the sensible outcome anyway.
Limitations and alternatives
The preparation is manual: for a thousand-name list, flipping is a project, and a spreadsheet with separate name columns is the better instrument. The sorter also cannot remove duplicates as it goes, so a list with the same person twice needs a pass through Remove Duplicate Lines first, and it cannot warn you that two different spellings, "Becker" and "Bekker", are probably the same family. It works on one pasted list in your browser; save the result as soon as it looks right.
Common mistakes
- Sorting the unprepared list and trusting it. A to Z on first-name-first lines produces first-name order: tidy-looking and wrong.
- Missing a line during preparation. One unflipped name files by its first name and breaks the surname sequence.
- Bulk-flipping a mixed list. Regular patterns flip cleanly; irregular names get mangled silently. Hand-check against the original.
- Sorting before deduplicating. The same person listed twice stays twice, now in two correctly sorted positions.
- Flipping back carelessly. If you restore first-name-first display, flip the words, not the order: the whole point is the new sequence.
FAQs
Is there a surname sort mode? No. The modes are A to Z, Z to A, numeric low to high, numeric high to low, shortest first, longest first and reverse order. Every one of them works on the line as written, starting from its first character.
My names are written as First Last with no comma. How do I flip them? If every line follows that exact pattern, a find and replace pass or a few minutes of editing can turn each line into Last, First form. Names with middle names, double surnames or titles break the pattern and are safer flipped by hand.
Do I have to change the names back after sorting? Only if the final list needs first-name-first display. Surname-first order is the standard form for indexes, registers and reference lists, so many lists can stay as they are.
Can it remove duplicate names while sorting? Not directly. Run the list through Remove Duplicate Lines first, then sort the cleaned result here.
Is my list of names uploaded? No. Sorting happens in your browser on your device.
Conclusion
Sorting by surname is a preparation problem wearing a sorting costume. The Sort Lines Tool orders lines by their opening characters, so the surname has to be the opening characters. Flip each line to surname-first form, sort A to Z, and you have a register in true surname order. The same rule makes the tool a natural fit for reference lists, whose entries already begin with the surname: see How to Alphabetize a Bibliography or Reference List. More tools for tidying text live in the Text and Writing Tools category.