CSV Sorter

When you only need the CSV sorted, opening Excel or LibreOffice just to click on a column header feels like a lot of ceremony. Paste the CSV, pick a column by position, choose ascending or descending, and the sorter emits the rows in natural order, item2 sits before item10 the way a human expects, not the way raw ASCII would put it.

How to sort your CSV

  1. 1

    Paste the CSV

    Header row optional. Use the checkbox to tell the sorter whether to freeze row 1 on top.

  2. 2

    Pick a column

    1-based index, e.g. `2` to sort by the second column.

  3. 3

    Choose direction

    Ascending by default. Toggle descending to flip the order.

  4. 4

    Copy the sorted CSV

    The output preserves the header (if present) and writes every data row in sorted order.

Natural sort versus lexicographic sort

The sorter uses PHP’s strnatcasecmp, which compares strings the way a person reads them: digits are treated as numbers and case is ignored.

Ordering comparison

Input values Lexicographic (default) Natural (this tool)
item1, item2, item10 item1, item10, item2 item1, item2, item10
Alice, bob, Carol Alice, Carol, bob Alice, bob, Carol
2024-01-01, 2024-2-1 2024-01-01, 2024-2-1 2024-01-01, 2024-2-1
file10.txt, file2.txt file10.txt, file2.txt file2.txt, file10.txt

Dates and numbers

  • ISO-8601 dates sort correctly as text (2024-01-15 before 2024-02-01). Use ISO dates whenever you can.
  • Ambiguous formats like 1/15/2024 do not sort correctly. Convert them to ISO first with a date formatter.
  • Numbers mixed with text sort naturally, so row2 beats row10 as a human would expect, but pure numeric sorting will be exact only when the cell contains nothing else. If you need strict numeric order, strip suffixes first with a text tool and sort the clean column.

Tips

  • Sort, then dedupe. When you run the Deduplicator after sorting, the “first row wins” rule becomes deterministic, you know which copy will be kept.
  • Stable sort is preserved: rows tied on the sort key keep their original relative order.
  • Single-column only. For multi-column sorts (sort by country, then by revenue), run the sorter twice: first on the secondary key, then on the primary. Natural sort is stable, so the secondary order survives.

Frequently Asked Questions

It does not, in this tool. The sorter uses natural-order comparison, so 2 precedes 10. If you are getting ASCII order, double-check that you are reading this tool’s output and not your spreadsheet’s raw sort.

Sort twice: first by the secondary key, then by the primary. The comparison is stable, so the secondary ordering survives inside groups of equal primary values.

No. Uppercase and lowercase letters compare equal, so alice and Alice are treated as the same string for ordering purposes.

No. Parsing and sorting happen entirely in your browser; the CSV stays on your device.

Related Tools

Tool available in other languages