Sort CSV rows by column

Order CSV rows by a selected column in ascending or descending text or numeric order.

freeworks offlinenothing uploaded
ToolCSV Sort
Input
Output
Put this on your own site

The frame below runs the same code as this page, in the reader's own browser. Nothing is sent to us, and nothing is sent to you.

Pick a dark background and the text and panels follow it, so the frame stays readable on a dark page.

Preview

How it works

The parser separates the header, compares one selected column as text or number, and serializes the reordered records. Numeric mode avoids lexical ordering for quantities.

  • The first column and ascending text order are predictable starting values.
  • Numeric comparison is explicit because strings sort digit by digit.

Worked example

Sort employees by age (numeric ascending)
Sort a 3-row CSV numerically by the age column
Input
											name,age,department
Carol,35,Design
Alice,30,Engineering
Bob,25,Marketing
										
Output
												name,age,department
Alice,30,Engineering
Bob,25,Marketing
Carol,35,Design
											

When to use this

Inventory lists sort stock, contact files sort surnames, and logs sort timestamps for triage.

Edge cases

  • Text order places 100 before 20, while numeric mode places 20 first.
  • Blank cells compare as empty values rather than disappearing.
  • Quoted commas remain part of the compared cell.

References