Staaarter

CSV Row Sorter

Sorts the data rows of a CSV (header excluded and kept fixed at row 0) by the values in a chosen column, identified by index or header name, with toggles for ascending/descending order and numeric versus lexicographic comparison. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-29
By Staaarter Team
rowstructuralsort

Overview

Introduction

Ordering a CSV's rows by date, amount, name, or any other column is one of the most common things people reach for a spreadsheet to do, and it's just as easy to do directly on the raw text.

This tool sorts data rows by a chosen column's values, with the header always staying fixed at the top where it belongs.

What Is CSV Row Sorter?

A structural CSV tool that reorders data rows (never the header row) based on the values in a single column, identified by 0-based index or header name.

It supports both ascending and descending order, and both numeric comparison (for columns of numbers) and lexicographic comparison (for columns of text).

How CSV Row Sorter Works

The input is parsed and padded to a uniform grid, split into the header row and data rows, and the sort column is resolved from the header.

The data rows are sorted using a stable comparator: numeric mode parses both cells as numbers (pushing non-numeric cells to the end), while lexicographic mode uses plain string comparison; the header is then reattached before re-serializing.

When To Use CSV Row Sorter

Use it to order rows chronologically, alphabetically, or by magnitude, an amount column, a date column, a name column, before reviewing or sharing a CSV.

It's also useful right before deduplicating or scanning a CSV manually, since sorted data makes near-duplicate or out-of-range values much easier to spot.

Features

Advantages

  • Keeps the header row fixed automatically, no separate step needed to protect it from the sort.
  • Numeric mode correctly orders numbers by magnitude rather than as text, so 9 sorts before 10.
  • Uses a stable sort, so rows with tied values keep their original relative order rather than shuffling unpredictably.

Limitations

  • Sorts by exactly one column per run; multi-column (primary/secondary key) sorting isn't supported directly.
  • Numeric mode treats any cell that doesn't parse as a number as larger than every valid number, which may not always match the intended ordering for mixed data.

Examples

Sorting numerically by an amount column

Input

id,amount
1,90
2,120
3,15

Output

id,amount
3,15
1,90
2,120

With numeric mode and ascending order on the "amount" column, rows are reordered from smallest to largest value; the header stays first.

Best Practices & Notes

Best Practices

  • Use numeric mode for any column of numbers, prices, quantities, IDs, since lexicographic mode would otherwise sort "10" before "9".
  • Check for empty or malformed cells in your sort column first if the results look off; they sort to the end in numeric mode.
  • Chain into CSV Column Extractor afterward if you only need to review the sorted values of one column.

Developer Notes

In numeric mode, each cell is validated with `a.trim() !== "" && !Number.isNaN(Number(a))` before comparing so blank or non-numeric cells consistently sort last regardless of direction, rather than corrupting the comparator with `NaN` comparisons; lexicographic mode falls back to plain `localeCompare`.

CSV Row Sorter Use Cases

  • Ordering rows chronologically or by amount before reviewing or sharing a report
  • Sorting a name or category column alphabetically for easier manual scanning
  • Preparing sorted data ahead of a deduplication or outlier-review pass

Common Mistakes

  • Forgetting to switch on numeric mode for a numbers column, which causes "10" to sort before "9" under plain text comparison.
  • Expecting a secondary sort key; only one column is used per sort, ties keep their original relative order rather than falling back to another column.

Tips

  • If a numeric sort looks wrong, check for stray whitespace or non-numeric characters in the column, they'll sort to the end rather than by magnitude.
  • For a two-key sort, run this tool twice: sort by the secondary key first, then by the primary key, relying on the stable sort to preserve the secondary order within ties.

References

Frequently Asked Questions