Home / Text tools / Sort lines numerically

Sort Lines Numerically

Sort lines by the number they contain, so 2 comes before 10. Negatives, decimals and thousands separators are understood.

Why alphabetical sorting gets numbers wrong

A normal text sort compares one character at a time, so 10 comes before 2 because the character 1 sorts before 2. Numeric sorting reads the actual value, so 2 comes first, then 10.

How the number is found

For each line the tool uses the first number it finds. That can be a whole line of digits or a number inside text, such as the 10 in Item 10. It reads:

  • negative numbers such as -3
  • decimals such as 7.5
  • thousands separators such as 1,250.50, which is read as 1250.5

Decimal commas, used in some countries, are not converted. Write decimals with a point.

Lines without a number

Choose where lines with no number go: at the bottom, at the top, or removed. They keep that position whichever direction you sort.

Example

The lines Item 10, Item 2, Price 1,250.50, notes only, -3 degrees, 7.5 kg and Item 1 sort to -3 degrees, Item 1, Item 2, 7.5 kg, Item 10, Price 1,250.50, with notes only at the bottom.

If numbers appear inside names, such as file2 and file10, the Natural method in the main sort tool may suit you better. For plain alphabetical order use sort lines alphabetically. See the sorting guide for more.

Frequently asked questions

How do I sort a list of numbers?

Paste one number per line, keep Ascending for smallest first, or choose Descending for largest first.

What happens to lines that contain no number?

You choose: they go to the bottom, to the top, or are removed.

Does it handle negative numbers and decimals?

Yes. Negatives such as -3 and decimals such as 7.5 are read correctly.

What if a line has several numbers?

The first number in the line is used for sorting. Ties are ordered by the whole line.