📋

Sort Lines

A line sorter reorders each line of pasted text by a rule you choose. Paste your list, pick Alphabetical, Numeric, By Length, Natural, Random or Reverse, and the result box updates as you type. Natural order is the one people expect from filenames: file10, file2, file1 comes back as file1, file2, file10, where plain alphabetical gives file1, file10, file2.

Input Lines
Output Lines
Removed

Embed this tool on your website

× px

                        

💡 Integration Tip

Copy the embed code and paste it into your website HTML. The responsive version adapts to all screen sizes automatically.

1 rating

Popular Tools

No more tools to show
Explore All Tools

About Sort Lines

The tool splits your text on line breaks and never touches the content of a line, so leading spaces, punctuation and casing survive the sort untouched. Six buttons choose the comparison. Alphabetical compares the whole line with the browser locale rules. Numeric reads the number at the start of each line, so 10, 9, 100, 2 comes back as 2, 9, 10, 100 rather than in text order. By Length sorts on character count. Natural mixes both, so digits inside a string compare as numbers. Random shuffles, and Reverse simply flips the current order.

Four checkboxes change what is compared and what survives. Descending flips the result, and it deliberately does nothing to Random or Reverse, which have no ascending direction. Case sensitive controls duplicate matching: with it off, Apple, apple and APPLE are the same line and Remove duplicates leaves one; with it on, all three are kept. Remove blanks drops lines that hold only whitespace, and Remove duplicates keeps the first occurrence of each line.

The three counters above the input make the effect of those checkboxes visible. Input lines is what you pasted, Output lines is what came back, and Removed is the difference. The sample the page opens with - banana, apple, cherry, date, apple, an empty line and fig - reads 7, 7 and 0 as it stands, and 7, 5 and 2 once Remove blanks and Remove duplicates are ticked.

Everything runs in your browser: the list you paste is never uploaded. Two things the tool does not do are worth knowing before you rely on it. Numeric mode reads any line without a leading number as zero, so a mixed list puts all the text lines before the positive numbers instead of rejecting them. And Case sensitive changes duplicate matching, not the sort order itself, because the alphabetical comparison uses locale rules that place apple before Banana either way.

Use Cases

A developer pastes a list of imports from the top of a file, sorts alphabetically, and pastes the block back so the diff in the pull request shows one ordering change instead of a scatter of moved lines.
A marketer cleaning a keyword export ticks Remove duplicates and Remove blanks, reads the Removed counter to see how many rows the export actually wasted, and copies the survivors into the planner.
A sysadmin ordering a list of exported filenames uses Natural rather than Alphabetical so backup-2 lands before backup-10 instead of after it.
A teacher preparing a spelling test pastes the week's words and presses Shuffle, then repeats it for a second group so the two classes get the same words in a different order.
A copywriter trimming a list of feature bullets sorts By Length to find the three longest lines, which are usually the ones that need rewriting before the page ships.

How to use

1

Paste your list into the input box, one item per line; the sample list already there can be selected and typed over.

2

Choose a mode in the button row: Alphabetical, Numeric, By Length, Natural, Random or Reverse.

3

Tick the options you need - Descending, Case sensitive, Remove blanks, Remove duplicates - and watch the Input lines, Output lines and Removed counters react.

4

Read the sorted list in the result box, which updates on every keystroke and on every option change without pressing anything.

5

Press Copy to take the result to the clipboard, Shuffle to switch straight to a random order, or the swap button to move the result back into the input for a second pass.

Pro Tips

  • Sort by length before you edit a list of bullets or menu labels: the longest lines rise to the bottom, and those are the ones that break a layout at 390 pixels.
  • Use Natural, not Alphabetical, whenever your lines end in numbers. On file10, file2, file1 the two modes disagree: Natural returns file1, file2, file10 and Alphabetical returns file1, file10, file2.
  • Case sensitive is really a deduplication switch here. Leave it off and Apple, apple and APPLE collapse to one line under Remove duplicates; tick it and all three survive. The alphabetical order itself barely changes.
  • Watch the Removed counter rather than counting by eye. On the shipped sample it jumps from 0 to 2 the moment Remove blanks and Remove duplicates are ticked, which tells you the list had exactly one blank and one repeat.
  • Descending has no effect in Random or Reverse mode, which is deliberate - neither has an ascending direction. To reverse a shuffled list, press Sort in Reverse mode after shuffling.

Troubleshooting

Problem:

The first line of the result is empty.

Solution:

Your list contains a blank line, and in alphabetical order an empty string sorts before every word. The shipped sample does exactly this. Tick Remove blanks to drop lines that hold only whitespace; the Removed counter will confirm how many were taken out.

Problem:

Numeric sorting put words at the top of the list.

Solution:

Numeric mode reads each line as a number and any line that does not start with one is treated as zero, so text lines gather at the bottom of the negative range - before every positive number. Sorting 10, apple, 2, banana returns apple, banana, 2, 10. Separate the numbers from the text, or use Alphabetical or Natural instead.

Problem:

Remove duplicates deleted lines that differ in capitalisation.

Solution:

Duplicate matching is case-insensitive until you tick Case sensitive. Apple, apple and APPLE are one line by default and the counter shows two removed. Tick Case sensitive and all three are kept. This is the checkbox to reach for when the capitalisation carries meaning, such as environment variable names.

Problem:

Descending does nothing.

Solution:

You are in Random or Reverse mode, where the option is ignored on purpose because neither has an ascending direction to flip. Switch to Alphabetical, Numeric, By Length or Natural and Descending takes effect immediately; to invert a shuffled list, run Reverse afterwards.

Problem:

Input lines says 1 when the box looks empty.

Solution:

An empty box still splits into one line, so the counter reads Input lines 1, Output lines 1 and Removed 0. That is arithmetic, not a fault. The same effect shows at the other end: a list ending with a newline counts one more line than you can see, because the text after the last break is an empty line.

Frequently Asked Questions

Paste the lines into the input box and leave the Alphabetical button selected - it is the default, and the result box fills in as you type. Tick Descending for Z to A. The comparison uses the browser locale rules rather than raw character codes, which is why apple sorts before Banana instead of after it.

Natural sorting reads runs of digits as numbers. Given file10, file2 and file1, Natural returns file1, file2, file10, while Alphabetical returns file1, file10, file2 because it compares "1" against "2" one character at a time. Use Natural for anything with a counter in the name: filenames, version strings, invoice numbers.

Tick Remove duplicates. The first occurrence of each line is kept and later repeats are dropped, and the Removed counter shows how many went. Matching ignores case unless you also tick Case sensitive: Apple, apple and APPLE collapse into one line by default, and stay as three lines when Case sensitive is on.

Excel sorts a column through Data then Sort, Word through the A-Z button in the Home ribbon, and Google Docs needs an add-on because sorting is not built in. All three work on a document you already have open. This page is quicker when the list is in a clipboard rather than a file, and it is the only one of the four that offers a natural or by-length order.

Yes - press By Length and lines are ordered by character count, shortest first, with Descending flipping that. The count includes spaces and punctuation, so "New York" is eight characters. On a list of aaa, a, aaaa, aa the tool returns a, aa, aaa, aaaa.

It reads them as zero rather than rejecting them. Sorting 10, apple, 2, banana numerically returns apple, banana, 2, 10 - the two text lines both count as zero, keep their original relative order and land before the positive numbers. If your list is mixed, sort it alphabetically first, or split the numbers out before using Numeric.

VS Code needs an extension or the built-in Sort Lines Ascending command from the palette, Notepad++ has Edit then Line Operations then Sort Lines, and Vim uses the :sort command with :sort n for numbers and :sort u to deduplicate. All three change a file in place; this page leaves your file untouched and gives you a block to paste.

By default yes, and in Alphabetical order a blank line sorts to the top because an empty string compares before every word. The sample list this page opens with has one blank line, which is why the first result row looks empty. Tick Remove blanks to drop every line that holds only whitespace, and the Removed counter tells you how many went.

No. The split, the sort and the counters all run in JavaScript on this page, so the text you paste never leaves the browser and nothing is stored between visits. That also means the list disappears when you close the tab - press Copy and paste the result somewhere before you leave.

Removed is simply Input lines minus Output lines, so it only moves when Remove blanks or Remove duplicates actually drops something. On the shipped sample it reads 0 until either box is ticked, then 2 - one empty line and one repeated "apple". If it shows a number you did not expect, one of those two checkboxes is on.

FreeWebTools AI
Powered by free AI models · Full chat →