Format Code Now
/

Sort Lines

TX-09

Paste text with one item per line and sort it A to Z, Z to A, by natural number order, or by line length. You can also just reverse the order of the lines.

Runs in your browser. Nothing is uploaded.

Lines

Sorted lines

How to use it

  1. Paste your lines into the input box, one item per line.
  2. Choose Sort by: Alphabetical, Natural, Length or Reverse the current order.
  3. Tick Descending for Z to A or longest first, and Ignore upper and lower case if capitals should not matter.
  4. Press Sort. The result updates as you change options.
  5. Copy the sorted lines or download them as a .txt file.

Alphabetical or natural order

Alphabetical sorting compares the text character by character, so file10.txt lands before file2.txt because 1 comes before 2. Natural order reads a run of digits as a number, so file2.txt comes before file10.txt, which is what people expect for numbered file names and versions. Both use your browser language rules (Intl.Collator), so accented letters sort next to their plain letters. Another browser or language setting can give a slightly different order.

Case, length and ties

With the default setting lowercase comes before uppercase for the same letter, so apple sorts before Apple. Tick Ignore upper and lower case to treat them as equal; equal lines then keep the order they had before. Sorting by length counts Unicode characters (code points), not bytes, so an emoji counts as one. Lines of the same length also keep their original order. Descending flips the order for every sort type except Reverse.

What happens to empty lines

Empty lines are sorted like any other line, so in ascending order they all come first. Remove them beforehand with the Remove Empty Lines tool if you do not want that. Line endings are kept as they were, and a final line break at the end of the text stays at the end. Numbers are not sorted by value unless you pick Natural, and Natural handles whole digit runs only, not decimals or negative signs.

Questions people ask

How do I sort lines alphabetically?

Paste your lines, leave Sort by on Alphabetical, and press Sort. The lines come back A to Z. Tick Descending for Z to A. The order follows your browser language rules, so accented letters sort next to their plain versions rather than at the end.

What is natural sort order?

Natural order treats a run of digits as a number instead of as separate characters. So file2.txt comes before file10.txt, where a plain alphabetical sort puts file10.txt first. It suits file names, version labels and numbered items. It reads whole digit runs only, so it does not understand decimals.

How do I sort lines by length?

Choose Length in Sort by. The shortest line comes first, or the longest first if you tick Descending. Length is the number of Unicode characters, so an accented letter or an emoji counts as one. Lines of equal length stay in their original order.

How do I sort lines case-insensitively?

Tick Ignore upper and lower case. Then apple, Apple and APPLE compare as equal and keep the order they had in your input. Without it, lowercase letters sort before the matching uppercase letter, so apple comes before Apple.

How do I reverse the order of lines?

Choose Reverse the current order in Sort by. The last line becomes the first and so on, with no sorting involved. The Reverse Text tool has a Reverse line order button that does the same thing.

Does it remove duplicate lines too?

No, it only reorders. Equal lines end up next to each other after sorting, which makes duplicates easy to spot. To delete them, run the sorted result through the Remove Duplicate Lines tool, which keeps the first copy of each.

About this tool

Alphabetical and natural sorting use your browser's Intl.Collator, so the order follows your language settings: accented letters sit next to their plain letters, and the result can differ from a plain byte-by-byte sort and from another person's browser. With the default settings lowercase comes before uppercase for the same letter (apple before Apple). Natural order reads digit runs as numbers, so file2 comes before file10; leading zeros are not treated specially. Length counts Unicode code points, not bytes, so an emoji counts as 1. Lines of equal length, and lines that compare as equal, stay in their original order. Reverse flips the current order and ignores the other options. Empty lines are sorted like any other line and come first in ascending order. Line endings and a final line break are kept.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.