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 trims the line, removes any leading characters that cannot be part of a number (anything except digits, e, E, ., +, -), and reads a decimal number from what is left. 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 readable number gets the value 0 and so lands among the zeros. 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

  • Putting words before the number. Leading letters are skipped, but the skipping stops at the first e or E, so item 10 and line 3 are read as 0 and are not sorted by their number, while v10 or id: 5 work.
  • 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 number in the middle or at the end of the line to count. Only the number at the start of the line (after any skipped prefix) is used.
  • 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 number each line starts with, 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. Paste in the lines, get back a correctly ordered list, and copy the result with one click.

Was this helpful?

You can pick up to 3 reactions.

Comments (0)

  • Be the first to comment.

Popular calculators

All Calculators