Skip to the content

Sort Lines Numerically

Sort a list by the number in each line, smallest first: 7 before 12, and 2.5 before 100. Text around the numbers is fine.

Lines in
0
Lines out
0
Duplicates
0
Share this tool:TwitterFacebookLinkedInWhatsAppEmail

Which number counts

Before
12 eggs 2.5 kg flour 100 g butter -4 degrees Milk 1,5 l water 7
After
-4 degrees 1,5 l water 2.5 kg flour 7 12 eggs 100 g butter Milk

Each line is sorted by the first number in it. The text before or after that number plays no part, so "Room 12" and "12 eggs" both count as 12.

  • A decimal can be written with a point or a comma: 2.5 and 1,5 are both understood. In 1,234 the comma is read as a thousands separator, because exactly three digits follow it.
  • A minus sign makes the number negative when it stands at the start of the line or after a space. In "page-5" and "2024-05-01" the hyphen is just a hyphen.
  • Lines without any number go to the end, in the order they came in.
  • Lines with the same number keep their original order.

This is not the same as alphabetical order, where 100 comes before 12 and 12 before 7, because there the characters are compared one at a time. It is also not the same as natural order, which reads the digits after a decimal point as a whole number and therefore puts 1.5 before 1.25.

For the largest number first, choose "By number, largest first" under Order.

Sorting, removing duplicates, numbering and adding a prefix can be combined on the Sort & Dedupe Lines page, which also remembers your settings.

See all 9