TextyConverterbeta
⌘K

Sort Numerically

Sort lines by the number they contain — 1, 2, 10 instead of 1, 10, 2. Handles signed integers and decimals.

About Sort Numerically

When sorted alphabetically, '10' comes before '2' because '1' < '2'. This tool sorts numerically instead — by extracting the first number from each line and comparing as floats. Lines without a number sort last (or first, in descending mode).

When to use it

  • Sorting log entries by line number or timestamp
  • Ordering a list of prices, counts, or IDs
  • Producing 'natural' order for filenames like file2, file10
  • Sorting decimal values from a CSV column

How it works

For each line, the first numeric token (including negative signs and decimals) is parsed via parseFloat. Lines are then sorted by that number. Lines with no parseable number are sorted to the end. Ties are broken by alphabetical order.

Examples

Numeric ordering instead of alphabetic
item 10
item 2
item 1
item 20
item 1
item 2
item 10
item 20

Frequently asked questions

Which number in the line is used?
The first one that appears. 'item-5 of 10' sorts by the 5, not the 10.
Are negative numbers and decimals handled?
Yes. The matcher accepts a leading minus and a decimal point: -3.5, 1.0, 42.
What about lines without numbers?
They sort to the end in ascending mode (or to the front in descending mode), so they stay grouped together rather than scattered.

Related tools