Tolz.me

Sort Lines Online

Sort lines alphabetically, in natural number order or by length, and remove duplicate or blank lines.

Options

Lines before

0

Lines after

0

Duplicates removed

0

Blank lines removed

0

Sorted list

Type or paste a list above, then copy the sorted result.

Sorting uses the collation rules of your browser, which is why accented and non-Latin letters end up where they read naturally. Numbers inside a line are compared as numbers in natural order, so item 2 comes before item 10.

About this tool

Sort lines online without opening a spreadsheet. Paste a list, choose A to Z, Z to A, natural order, or sort by line length, then remove duplicates, trim the blanks and drop the empty lines. The counters show how many lines went in and how many came out, and the result is plain text that pastes straight back where it came from.

Browse more text tools or explore all Tolz.me tools.

Try other relevant tools

Frequently asked questions

How do I sort lines alphabetically?+

Paste one item per line into the box, leave the sort order on A to Z, and copy the result. Sorting uses the collation rules of your browser, so accented letters sit next to the letters they belong with.

What is the difference between A to Z and natural order?+

A to Z compares numbers as text, so item 10 comes before item 2. Natural order reads them as numbers, so item 2 comes first. Use natural order for numbered lists, versions and file names.

How do I sort lines by length?+

Pick Shortest first or Longest first in the sort order. Lines of the same length fall back to alphabetical order, which is handy for spotting the one line that does not belong.

Can I remove duplicate lines?+

Yes. Turn on Remove duplicate lines and the first copy of each line is kept while the rest are dropped. By default two lines count as duplicates only when they match exactly, and you can switch that off to treat Apple and apple as the same line.

Does the sort keep capital letters in a separate place?+

It depends on the case setting. With case ignored, Banana and banana land next to each other, which is what most people want for a list of names. With case respected, the capital letter sorts first, the way the Unicode collation rules treat it.

Is the text uploaded to a server?+

No. Sorting happens in your browser, so the list stays on your device and nothing is stored.

Why is there one more line in the output than I expected?+

A file that ends with a line break has an empty line after the last item. Turn on Remove empty lines and the count matches what you see.

Use cases

  • Order a keyword list before running it through a spelling or thesaurus check.
  • Sort names or usernames so duplicates sit next to each other and stand out.
  • Put a list of file names or tags into a predictable order for a commit or a ticket.
  • Trim a list down to a set budget by sorting the lines by length.
  • Clean a list that came from a spreadsheet, with blank lines and repeats removed.

Sort Lines Online

Sorting a list of lines is a small job that comes up more often than you would think: cleaning a word list, ordering a column of names, tidying a list of file names, or putting a set of tags into a sensible order. This tool sorts lines alphabetically or by length, removes duplicates and blank lines, and gives you the result as plain text you can paste anywhere.

What sorting lines is good for

A list of lines is the most basic piece of data there is: one record per line, no header, no columns. A keyword list for an export. A list of usernames to check. The names of the files in a folder, copied out of a terminal. Tags for a post. The lines of a config file. Every one of those gets easier to work with once the order is predictable.

Sorting also exposes duplicates. Put a list of names in alphabetical order and the repeats sit next to each other, which is the fastest way to see them. The tool can remove them for you and tell you how many went.

The sort uses the collation rules of your own browser, which is a small but real difference from a plain byte comparison. Letters with accents sit next to the letters they belong with, and the order matches the way a dictionary in your language would order the words, rather than putting every accented letter at the end of the list.

The sort orders explained

Five orders are available, and they answer different questions. Two of them sort alphabetically, one of them understands numbers, and two of them sort by size.

Alphabetical order

A to Z is the standard alphabetical order. Z to A is the same list turned around.

Case can change the order. With case ignored, Banana and banana land in the same place, which is what most people want for a list of names. With case respected, the capital letter sorts first, because that is how the Unicode collation rules treat it.

Natural order for numbers

Natural order is the one to reach for when your lines contain numbers: it reads item 2 before item 10, and version 9 before version 10, instead of putting item 10 first because the digit one comes before the digit two.

It also handles mixed lines such as Part 12 and Part 3, which plain alphabetical order would place the wrong way round.

Shortest first and longest first

These two sort by character count. They are useful for finding the odd line out in a list, for trimming a list down to a set budget, or for putting the important lines at the top of a review.

When two lines have the same length, they fall back to alphabetical order, so the result stays stable and does not shuffle between runs.

How to use it

Paste your list into the box, one item per line. If the text comes from a spreadsheet, copy the column first so the list arrives without the column letters on the side.

Choose the sort order from the dropdown. Then set the options you need: ignore case, remove duplicates, trim the blanks off each line, and remove the lines that hold nothing. The counters under the options show how many lines went in, how many came out, and how many duplicates and blank lines were dropped.

The Shuffle button randomises the order, which is useful when you want to pick a random line from a list or split a list between people. Change any option afterwards and the list goes back to the sorted order.

Copy the result with the button at the bottom. The output is plain text with one line per item, so it pastes straight into a form, a file, or a spreadsheet cell.

A worked example

Here is a list of tags that came out of a spreadsheet, with a blank line in the middle, an extra space on one line, and one tag repeated. The sort order is A to Z with case ignored, so Banana and banana would have sat next to each other.

The duplicate is dropped when the duplicates switch is on, the blank line disappears, and the extra space on the cherry line goes away because trimming is on. The counters report six lines in and four lines out, with one duplicate and one blank line removed.

Before              After
apple               apple
Banana              banana
                    cherry
 cherry             lime
apple
lime

Changing the result

If the list held both Banana and banana, turning the case sensitive duplicate option off would treat them as the same line and leave three lines in the result instead of four. That option is the one to check when a list of names looks like it is missing somebody.

Change the order to natural and a list of numbered files sorts the way you would say it out loud: file 2, file 9, file 10, rather than file 10, file 2, file 9.

Removing duplicates and blank lines

Duplicate removal keeps the first copy of each line and drops the rest, so the order of the surviving lines still follows your list. It runs before the sort, which means the copy that survives is the one that appeared first in the input.

By default, two lines are duplicates only when they match exactly. Switch off the case sensitive option and Banana and banana are treated as the same line, which is the right choice for a list of names that were typed by different people.

Removing blank lines takes out any line with nothing but spaces in it. It is worth switching on when a list came from a document, because a stray empty line at the end is the usual reason a paste into a form produces an extra entry.

Trimming removes spaces and tabs from both ends of every line. It does not change the order, and it does not touch spaces inside a line, so a phrase such as New York stays intact.

Tips

Paste one column at a time. If you copy a block of cells from a spreadsheet, each line may hold several tab separated values. Sort that, and the tabs travel with the lines, which usually still works but makes the order harder to read.

Sort by length first when you are looking for a line that does not belong. An address that is twice as long as the rest of a list of names stands out immediately.

Check what is in the list before you remove duplicates. If the entries are URLs, a trailing slash or a difference in capitalisation may be the point of the entry, and folding them together loses information.

The output always uses plain line breaks, so pasting into a spreadsheet puts one value in each row.

Troubleshooting

If the order looks wrong, check the case option first. With case respected, a capital letter sorts ahead of a lower case one, and a list that mixes both can look scrambled even though it is sorted correctly.

If numbers come out in the wrong order, switch to natural order. A to Z compares numbers as text, so 10 comes before 2.

If the list has a stray blank line at the end, that is normal. A text file that ends with a line break has an empty line after the last item, and the counters will show one more line than you expected until you switch on the blank line removal.

If a line is missing after you copy, it probably held a tab or a leading space that the tool trimmed. Turn trimming off to keep the line exactly as it was.

If the sort seems to ignore part of a line, the part is probably a hidden character. The invisible character remover will find and list it for you.

Explore more text tools on Tolz.me.

Related tools