Skip to content
Devtoolry

Sort Lines

Sort lines of text online alphabetically, naturally (item 2 before item 10), by number or by length, in ascending or descending order. Runs in your browser.

Something not working, or missing a feature? Send feedback

About the Sort Lines

The Sort Lines tool sorts a list alphabetically, naturally (so item 2 comes before item 10), by a leading number or by length, ascending or descending. It can also reverse the current order, drop empty lines and remove duplicates in the same step.

Everything runs in your browser, so your input is never uploaded to a server.

How to use the Sort Lines

  1. Paste your text, one item per line.
  2. Pick the sort order and the direction, and choose whether upper and lower case are sorted separately.
  3. Optionally remove duplicates and empty lines, then copy or download the sorted list.

Examples

Natural sort of file names

Input

file10.txt
file2.txt
File1.txt
file20.txt
file3.txt

Result

File1.txt
file2.txt
file3.txt
file10.txt
file20.txt

Numbers are compared by value, and upper and lower case are sorted together.

The same list sorted alphabetically

Input

file10.txt
file2.txt
File1.txt
file20.txt
file3.txt

Result

File1.txt
file10.txt
file2.txt
file20.txt
file3.txt

Character-by-character comparison puts file10.txt before file2.txt. This is why natural sort is the default.

Largest number first

Input

42 Oslo
7 Paris
-3 Reykjavik
100 Lima
Tokyo

Result

100 Lima
42 Oslo
7 Paris
-3 Reykjavik
Tokyo

Lines are ordered by their leading number. Tokyo has no number, so it goes last in either direction.

Common mistakes

  • Alphabetical sort for numbered items. Alphabetical order puts 10 before 2. Use natural or numeric sort for anything with numbers in it.
  • Sorting lines that belong together. Sorting works line by line, so multi-line records (such as addresses) get split apart. Put each record on one line first, for example as CSV.

Works well with the Sort Lines

Frequently asked questions

What is natural sort?

Natural sort compares numbers inside text by value, so file2.txt comes before file10.txt. A plain alphabetical sort compares character by character and puts file10.txt first, because "1" sorts before "2".

How does numeric sort work?

Lines are ordered by the number they start with, including negative and decimal numbers. Lines that do not start with a number go to the end.

Is sorting the same in every language?

This tool uses English collation rules for consistent results. Accented letters sort next to their base letter, for example é next to e.