ModernCalcs

CSV Sorter

Sort CSV rows by any column, ascending or descending. Toggle numeric mode for number columns like salary or age.

CSV Input

Sorted CSV

Select a column and click Sort

CSV Sorter: Order Your Data Without a Spreadsheet

Sorting CSV data alphabetically or numerically should not require opening Excel or writing a script. Select a column, pick a direction, toggle numeric mode for number fields, and get a sorted CSV back instantly — ready to copy or use directly.

Formula
rows.sort((a, b) => { const va = numeric ? +a[col] : a[col]; const vb = numeric ? +b[col] : b[col]; return dir === "asc" ? va > vb ? 1 : -1 : va < vb ? 1 : -1; })

JavaScript's Array.sort() is stable in all modern engines, so rows with equal sort key values preserve their original relative order.

Numeric vs Alphabetic Sort

Alphabetic sort compares values as strings, which gives correct order for text but wrong order for numbers — '10' sorts before '9', and '2' sorts before '100'. Numeric mode parses values as numbers before comparing, giving the expected order: 2, 9, 10, 100. Enable numeric sort for any column that contains numbers: prices, counts, IDs, scores.

Ascending and Descending

Ascending (A→Z, 0→9) is the default and most common sort direction. Descending (Z→A, 9→0) is useful when you want the largest or most recent values at the top — sales ranked by revenue, log entries by timestamp, or users by account age.

Stable Sort

JavaScript's Array.sort() is stable in all modern engines, meaning rows with identical values in the sort column preserve their original relative order. If your data has secondary sort requirements, apply the sort multiple times — secondary column first, then the primary column.

Practical Examples

Sorting a Sales Report by Revenue Descending

Rank sales reps from highest to lowest revenue.

  • 1.Paste the CSV with columns like rep_name, deals_closed, revenue
  • 2.Select the 'revenue' column from the sort column dropdown
  • 3.Toggle 'Numeric' mode since revenue is a number
  • 4.Select 'Descending' and copy the result

Sort Controls

  • Sort by any column selected from the header row
  • Ascending (A→Z, 0→9) or descending (Z→A, 9→0)
  • Numeric mode for correct number ordering (9 < 10 < 100)
  • Stable sort: equal values preserve original row order

Good Use Cases

  • Ranking sales, traffic, or performance data by a numeric metric
  • Sorting log exports by timestamp or severity
  • Alphabetizing name or product lists for human review
  • Ordering reference data before importing into a database

Frequently Asked Questions

What is the difference between numeric and alphabetic sort?

Alphabetic sort compares values as strings, so '10' comes before '9' and '100' comes before '20'. Numeric sort compares values as numbers, giving the correct order: 9, 10, 20, 100.

Is the header row included in sorting?

No. The header row is always kept at the top and only the data rows are sorted.

Can I sort by multiple columns?

This tool sorts by a single column. For multi-column sorting, apply the sort multiple times starting with the least significant column.