How to Sort Lines of Text Alphabetically, by Number or by Length
By Tools Star Hub Editorial Team · Published
Quick answer: paste one item per line into the Line Sorter, pick a mode (A → Z, Z → A, Numeric ascending, Numeric descending, Shortest → longest or Longest → shortest), and sort. Case-insensitive is on by default so “apple” and “Apple” sit together. You can also trim spaces before comparing, ignore empty lines, and remove duplicates in the same pass, then copy the result or download sorted.txt.
Sorted lists are easier to scan, compare and check for gaps. Alphabetizing names, tags, file lists or glossary terms by hand is slow and error-prone, and a spreadsheet is overkill when all you have is a column of text.
What does each sort mode do?
The two text modes compare lines character by character. The two numeric modes look for a number at the start of each line. The two length modes count characters. When two lines tie, their original order is kept, which is called a stable sort.
| Mode | Compares | Tie-breaker |
|---|---|---|
| A → Z / Z → A | Characters from left to right | Original order |
| Numeric ascending / descending | The number at the start of the line | Lines without a number go last, sorted A → Z |
| Shortest → longest / Longest → shortest | Number of characters | A → Z, then original order |
Why does 10 come before 9 in alphabetical order?
Text sorting compares the first character first. “1” comes before “9”, so “10” lands ahead of “9” no matter how many digits follow. File names such as photo10 and photo9 behave the same way.
Use Numeric ascending when the lines start with numbers. The tool reads the leading number, including a minus sign and decimals such as -2.5, and sorts by its value. Lines that do not start with a number, or start with a symbol such as $ or #, are placed after the numeric lines. A comma inside a number stops the reading, so “1,200” is read as 1; remove thousands separators first if they matter.
Numbers in the middle of a line, such as “Chapter 10”, are not used by the numeric modes. Put the number at the start, or pad with zeros (Chapter 09, Chapter 10), so plain A → Z sorting works.
How do capital letters and accents affect the order?
With Case-insensitive on, letters are compared as lowercase, so “banana”, “Banana” and “BANANA” sit together. Switch it off and the order follows character codes, where all capitals come before all lowercase letters. That puts “Zebra” above “apple”.
The comparison is by character code rather than the rules of a particular language. Accented letters such as é or ö sort after z, and letters from other alphabets sort after Latin letters. That is predictable for codes and identifiers, but it differs from a dictionary. If you need strict language-aware order for names, a spreadsheet’s sort with the right locale is the better choice.
Can I clean the list while sorting it?
Yes. Trim before comparing ignores spaces at the ends of lines, so “ pear” is not pushed to the top because of a leading space. The lines are output as they were, with the spaces still there. Ignore empty lines removes blank rows. Remove duplicates keeps the first copy of each line and respects the case and trim settings.
For heavier cleanup, such as collapsing double spaces inside lines, run the text through the Whitespace Remover first. The tool shows how many lines went in and how many came out, which is a quick check on how much was removed.
When is sorting by length useful?
Length sorting helps you spot outliers: the shortest lines are often typos or empty entries, and the longest may be two items accidentally joined. Writers use it to find long headlines or titles that will be cut off, and developers use it to tidy lists of imports or keys. Length counts every character, including spaces, unless Trim before comparing is on.
What are common reasons to sort lines?
Glossaries, bibliographies, guest lists, team rosters and tag lists are easier to read in alphabetical order. Developers sort configuration keys, dependency lists and import lines so that changes show up clearly in a code review. Data checks are another use: sorting puts near-identical entries next to each other, so typos such as “Karachi” and “Karachii” become obvious.
Numeric sorting suits scores, prices with the number first, rankings and timestamps written as plain numbers. Reverse modes are useful for leaderboards and for seeing the newest or largest items first.
Is this the same as sorting in a spreadsheet?
Not quite. Spreadsheets sort rows of cells and usually apply language-aware rules, so accents and case are treated the way a dictionary would treat them. They can also sort by several columns at once.
The Line Sorter treats each line as a single piece of text and compares character codes. That makes the order consistent and easy to predict, and it is fast for a single column of values copied from anywhere. For tables with several fields, or names that must follow a particular language’s alphabet, use a spreadsheet.
Is my list sent anywhere?
No. Sorting happens in your browser tab, and the list is not sent to Tools Star Hub. You can paste customer names, email lists or internal notes without them leaving your device.
How do I sort dates or times?
Write them so that text order matches time order. The year-month-day format, such as 2026-03-09, sorts correctly with plain A → Z, as long as months and days always use two digits. Formats like 9/3/2026 or March 9 do not, because the text order follows the first characters rather than the calendar.
Times written as 24-hour values with two-digit hours, such as 07:45 and 18:10, also sort correctly as text. If your list uses a mix of formats, tidy them first with Find and Replace, then sort.
Can I get my original order back?
Yes, as long as you keep the original. The sorted output appears in a separate Result box and your pasted text stays in the input box, so you can try different modes and options without losing anything. If you need to restore an order later, number the lines with Add Line Numbers before sorting; sorting numerically by those numbers puts everything back where it started.
How to sort lines online
- Paste the list. Put one item per line. The tool accepts up to 400,000 characters.
- Choose a mode. Pick A → Z, Z → A, a numeric order, or a length order.
- Set the options. Leave Case-insensitive on for most lists, and add trimming, empty-line removal or deduping as needed.
- Sort and save. Sort, check the line counts, then copy the result or download sorted.txt.
Example
Fixing a numbered list
Lines “10 Rome”, “2 Paris” and “1 Oslo” sorted A → Z give 1, 10, 2. Numeric ascending gives 1 Oslo, 2 Paris, 10 Rome.
Alphabetizing a messy tag list
Tags include “SEO”, “seo ” and blank lines. With Case-insensitive, Trim, Ignore empty lines and Remove duplicates on, you get one “SEO” entry in a clean A → Z list.
Finding the longest product titles
Choose Longest → shortest to see which titles are likely to be truncated in a store listing, and edit those first.
Tips and limitations
One item per line
Comma-separated values on one line are treated as a single line. Use Find and Replace to turn commas into line breaks first.
No multi-column sorting
The tool sorts whole lines. For sorting CSV rows by a specific column, use a spreadsheet.
Number the result
Add positions to a sorted list with the Add Line Numbers tool.
FAQ
- Why does Z come before a when I sort?
- Case-insensitive is off, so capitals sort before lowercase letters. Turn it on to mix them together.
- How do I sort in reverse alphabetical order?
- Choose Z → A.
- Where do lines without numbers go in a numeric sort?
- After all the lines that start with a number, in A → Z order.
- Can it sort negative numbers and decimals?
- Yes, when they are at the start of the line, such as -3 or 2.75.
- Does trimming change my output?
- No. Trim affects only the comparison; the lines are output with their original spacing.
- Is the sort stable?
- Yes. Lines that compare as equal keep their original order.
- Why are accented words at the end of the list?
- Lines are compared by character code, and accented letters have codes after z.
- Can I sort and remove duplicates in one step?
- Yes. Tick Remove duplicates; the first copy of each line is kept.
- Does it sort numbers with thousands separators?
- Not reliably. The number is read up to the comma, so remove separators first.
- How do I save the sorted list?
- Copy it or use Download .txt to save sorted.txt.
- How do I sort case-insensitively?
- Lowercase a copy for ordering, or use a case-insensitive mode if the tool offers one.
- Can I sort by the second column of a TSV?
- Not directly—extract that column, sort it with keys, or use a spreadsheet for field sorts.
- Where do blank lines go after sorting?
- They usually cluster at the start or end depending on how empty strings compare.
- How should version strings like 1.10 vs 1.2 sort?
- Plain text puts 1.10 before 1.2; use numeric or natural sort when available.
- Can I randomize lines instead of sorting?
- This guide focuses on ordered sorts; shuffling needs a separate randomize step.
- Does locale change alphabetical order?
- Accent and language rules can; stick to one locale when comparing team outputs.
- How do I sort dates written as text?
- Prefer ISO YYYY-MM-DD so lexicographic order matches chronology.
- Will sorting ruin paired name/email lines?
- Keep pairs on one line (name, email) so they move together when sorted.
- Can I sort descending numbers for leaderboards?
- Use numeric sort with reverse order so 100 appears above 20.
- Should I trim before sorting names?
- Yes—leading spaces can push entries out of true alphabetical position.
Put any list in order with the free Line Sorter.
To drop repeated lines without sorting, use the Duplicate Line Remover.
To number the sorted lines, try Add Line Numbers.