Skip to content

Sort Lines Alphabetically

Alphabetical, reversed, or shortest first.

Sorting a list is the fastest way to make it reviewable. Alphabetical order groups related entries together, makes gaps obvious, and turns a scan for a specific item into a quick jump rather than a full read.

The sort here is natural rather than strictly character-by-character, which matters as soon as numbers appear. A plain sort puts item10 before item2, because the character "1" comes before "2". Natural ordering compares the numbers as numbers, so item1, item2, item10 come out in the order a person expects.

Three orders are available. A to Z is the default. Z to A reverses it, which is useful when the most recent or highest-value entries sort last. Sorting by length puts the shortest lines first, which is a quick way to spot truncated entries, stray fragments, or the one line that is far longer than the rest.

Examples

Examples for Sort Lines Alphabetically: each row pairs an input with the output it produces.
What it handles Input Output
A to Z banana apple cherry apple banana cherry
Natural number order item10 item2 item1 item1 item2 item10
By length ccc a bb a bb ccc

How it works

Lines are compared with a locale-aware collator configured for numeric ordering and base sensitivity. Locale awareness means accented characters sort next to their unaccented counterparts rather than being pushed to the end, so café sorts near cafe instead of after z. Base sensitivity means case does not decide the order, so Apple and apple sort together instead of splitting into separate blocks. Numeric ordering is what produces the natural item1, item2, item10 sequence. Sorting by length counts characters as Unicode code points rather than storage units, so an accented letter or an emoji is not double-counted and does not get pushed to the end of the list as if it were the longest line; a multi-part emoji built from several joined symbols still counts each part. Equal-length lines fall back to alphabetical order, so the result is stable and predictable.

When people use it

  • Alphabetizing a list of names, tags, or terms before publishing.
  • Ordering filenames or identifiers that contain numbers.
  • Finding the outliers in a list by sorting on length.
  • Preparing a glossary or index from unordered notes.

Frequently asked questions

Does uppercase sort before lowercase?
No. Case is ignored when deciding the order, so Apple and apple stay together instead of forming two separate groups.
How are accented characters handled?
They sort next to their base letter, so résumé sits near resume rather than at the end of the list.
Are duplicates removed?
No. Sorting only reorders. Run the duplicate remover first if you want a unique, ordered list.
How do I alphabetize a list?
Paste the list with one item per line and choose A to Z. The ordering is locale-aware and case-insensitive, so café sorts next to cafe and Apple next to apple instead of forming a separate block, and numbers are compared as numbers, so item2 comes before item10.
Are blank lines kept?
Yes, and they sort to the top. Use the whitespace trimmer beforehand if you would rather drop them.