Sort Lines Numerically Tool

Paste lines of text to sort them by their leading numeric value.

Result

-8 ms cache 7.5 ms ping 42 ms login 250 ms checkout 1200 ms report
5

How it is calculated

Each non-empty line is given a sort key: the tool reads the first number anywhere in the line, such as the 12 in Item 12, the 3.5 in Price: 3.5 or the -4 in -4 x. A minus or plus sign counts only at the start of a word, so A-2 is read as 2. Lines are then sorted ascending by that value, and blank lines are dropped. Lines with equal values keep their original order. A line with no number at all goes last, in its original order. Only a dot works as the decimal point, and a thousands comma ends the number, so 1,000 counts as 1. The count shows how many lines were sorted. There is no descending option, so reverse the output yourself if you need it.

Worked example

You paste five response times, each starting with a number: 250, 42, 1200, -8 and 7.5. A plain alphabetical sort would put 1200 first and 7.5 near the end. The tool reads the leading numbers instead and orders them -8, 7.5, 42, 250, 1200. The negative value comes first because it is the smallest. The output is the five full lines in that order (the label after each number travels with it), and the line count shown is 5.

Try this example →

Common mistakes

  • Expecting a minus sign inside a word to count. A sign counts only at the start of a word, so A-2 is read as 2, not -2; put a space before the minus if you mean a negative number.
  • Using a decimal comma or a thousands separator. 7,5 is read as 7 and 1,000 as 1; write 7.5 and 1000.
  • Expecting a later number in the line to count. Only the first number in each line is used, so Dec 5 - 12 items is sorted by 5.
  • Expecting a descending order, or sorting by a second column. Only ascending order by the first number is offered.
  • Expecting blank lines to be preserved. Empty lines are removed, which also lowers the count compared with the lines you pasted.

About this calculator

This tool sorts pasted lines of text in ascending order by the first number in each line, rather than treating the line as plain text. That distinction matters because ordinary alphabetical sorting compares characters left to right, so "100" sorts before "9" — a numeric sort instead compares the actual magnitude of the leading number, putting 9 before 100 as expected.

It's built for exactly the kind of data that trips up plain sort commands: server logs with numeric prefixes, exported spreadsheet rows, measurement readings, or any list where the meaningful order is numeric rather than lexicographic.

Was this helpful?

You can pick up to 3 reactions.

Comments (1)

  • Editorial team

    For dependable results, make sure the number you want to sort by is the first number on each line. The tool takes the first number it finds, wherever it stands, so Item 12 sorts by 12, and lines with no number go to the bottom. Write 1000, not 1,000, since a comma ends the number. It sorts ascending only; for a descending list, read the output from the bottom. What do your lines look like?

Popular calculators

All Calculators