CSV Sort
Sort CSV locally by up to three text or exact decimal keys, preserving IDs and equal-key row order.
This tool runs entirely in your browser. Your data is never uploaded, never stored, and never leaves your device.
Sort complete CSV rows by up to three text or exact decimal keys, preserving field text and source order for equal keys.
How to use it
- 1Load CSV and read its columns.
- 2Choose up to three keys, comparison modes, directions and empty-field placement.
- 3Sort, inspect the preview and download the full CSV.
Example
- Input
- id,score 001,10 002,2 Sort score numerically
- Output
- id,score 002,2 001,10
What happens to your data
Sorting runs locally in browser memory without uploading your CSV. Cell text is preserved unless optional formula protection is explicitly enabled; spreadsheet applications may still reinterpret imported fields.
Last updated October 2026
Sort CSV records by one, two or three columns without separating a row from its values. Choose text comparison for identifiers or exact decimal comparison for amounts and long integers. A second or third key breaks ties in the preceding key; rows equal under all keys keep their original order.
This is useful when an export needs deterministic ordering before a comparison or import. It does not change cell values, infer dates or silently round long numeric identifiers.
How it works
Read the columns, choose the first key, and optionally add up to two more keys. Each key has its own ascending or descending direction and text or decimal comparison. Keys must use distinct columns. Text ordering compares UTF-16 code units and is deterministic, not a locale-aware alphabetical or natural-number ordering. Thus text 10 sorts before text 2. Ignore case applies JavaScript lowercase conversion to comparison keys only; original text is preserved. No whitespace trimming occurs in text mode.
Exact decimal mode compares signed decimal strings without converting them to binary floating-point values. Decimal points and scientific notation are supported, with up to 1,024 coefficient digits and an exponent between −1,000 and 1,000. Surrounding whitespace is ignored only for the comparison. Numeric equivalents such as 2, 02 and 2.0 tie, so their source order is retained unless a later key differs. Currency symbols, grouped thousands, NaN, Infinity and unsupported number forms stop the sort with a row and column location. They are not moved silently to another group.
Choose empty fields always first or always last. This policy applies independently of ascending or descending direction. Only a zero-length cell is empty; whitespace-only fields remain text and fail decimal mode. Full rows move together, the header stays first, and no data row is removed. Header-only CSV is valid.
For example, sorting id,score records 001,10 then 002,2 then 003,2 by score ascending gives 002,2 then 003,2 then 001,10. The two records scoring 2 retain their source order and every ID retains its zeros.
Load a UTF-8 CSV or paste text, then choose comma, semicolon or tab explicitly. Inputs are limited to 2 MiB, 10,000 records including the required header, 200 columns and 200,000 cells. Headers must be nonempty and exactly unique. Malformed quotes, unequal field counts and invalid UTF-8 files are rejected, not silently repaired. Quoted commas, escaped quotes and multiline fields stay in their original cells. Output is capped at 10 MiB; exceeding a limit produces an error rather than a partial download. CSV downloads use UTF-8 without a BOM and CRLF record endings; original quoting style and line-ending bytes are not preserved. Preview displays up to eight rows and six columns with long values abbreviated; the complete download includes all rows and cells.
Optional spreadsheet-formula protection adds an apostrophe to formula-like exported cells, including negative numbers and some headers. It is off by default to preserve text. Protection is an explicit text change, not a universal spreadsheet-security guarantee, and a newly colliding header causes an error. Import identifier columns as text when opening CSV in a spreadsheet.
Processing stays in browser memory; the tool does not upload cell contents or connect to your database. Editing the source removes previous results, and a late file read cannot overwrite a newer edit. Changing output options also clears an old result. Downloads can contain confidential data and remain your responsibility.
Worked example: Sort numeric scores without losing ID zeros
- Input
- id,score 001,10 002,2 003,2 Sort score as decimal ascending
- Result
- id,score 002,2 003,2 001,10
Equal scores keep their original order. Sorting text instead would place 10 before 2.
Common use cases
- Ordering a CRM export before a controlled import
- Comparing long numeric identifiers without floating-point rounding
- Sorting by department then amount with separate directions
- Preparing deterministic CSV fixtures while keeping equal-key order
Frequently asked questions
Will sorting change my leading-zero IDs?+
No. Sorting changes row order, not field text. Decimal mode can treat 001 and 1 as equal for comparison while exporting each original spelling unchanged. Spreadsheet applications can still reinterpret IDs when they open CSV.
What happens to invalid numeric cells?+
The operation stops with a data-row and column location. Choose text mode or correct the source; the tool does not silently round, discard or reorder malformed numeric fields.
Why is text 10 before text 2?+
Text mode compares UTF-16 code units rather than numeric magnitude. Choose exact decimal mode for numeric order. Natural sorting of mixed text such as item2 and item10 is not supported.
Are empty cells reversed in descending mode?+
No. Empty first or last is an explicit policy independent of direction. A cell containing spaces is not empty.
Can I sort by dates or multiple columns?+
Up to three distinct columns are supported. Dates are never parsed or inferred; uniformly formatted ISO dates may have useful text ordering, but mixed formats and time zones require explicit normalization elsewhere.
Related tools
CSV Filter
Filter CSV rows, select output columns and download a focused table without uploads.
CSV Data Profile
Inspect CSV column counts, empties, distinct values and duplicate rows locally; export a JSON profile.
CSV Column Editor
Keep, reorder and rename CSV columns without changing cell values or row order.
CSV to SQL
Convert CSV to SQLite, PostgreSQL or MySQL INSERT scripts while preserving IDs as text.