CSV Column Sorter
Reorder CSV columns by drag-and-drop or keyboard. Upload, rearrange, preview and export sorted CSV files instantly in your browser.
About
CSV files exported from databases, APIs, or spreadsheets rarely arrive with columns in the order you need. Manually rearranging columns in a text editor risks corrupting quoted fields, breaking escaped delimiters, or silently dropping data. This tool parses CSV input in compliance with RFC 4180, correctly handling quoted fields containing commas, newlines, and escaped double-quotes (""). It auto-detects the delimiter (d) by frequency analysis across the first 20 rows, supporting comma, semicolon, tab, and pipe characters. You reorder columns visually and export a correctly re-quoted file.
The tool operates entirely client-side. No data leaves your browser. It handles files up to 50 MB and displays a live preview of the first 100 rows. Note: this tool assumes rectangular data. Rows with inconsistent column counts are flagged but preserved. For fixed-width or multi-character delimiter formats, pre-convert to standard CSV first.
Formulas
Delimiter auto-detection scores each candidate delimiter d by computing the modal column count across sampled rows:
The delimiter with the highest consistent score (and score > 0) is selected. Column reordering applies an index permutation Ο to each row:
Where k is the total column count and Ο is the user-defined column order. Fields requiring quoting are wrapped per RFC 4180: any field containing the delimiter d, a double quote ", or a newline character is enclosed in double quotes, with internal quotes escaped as "".
Where d = active delimiter, field = cell content string, Ο = permutation array of column indices, k = number of columns, n = number of sampled rows for detection (max 20).
Reference Data
| Delimiter | Character | Common Source | Auto-Detected | RFC 4180 | Notes |
|---|---|---|---|---|---|
| Comma | , | Excel, Google Sheets, APIs | Yes | Yes | Default standard delimiter |
| Semicolon | ; | European Excel, SAP | Yes | No | Used where comma is decimal separator |
| Tab | \t | TSV exports, databases | Yes | No | Common in bioinformatics data |
| Pipe | | | Legacy systems, mainframes | Yes | No | Rarely appears in field data |
| Double Quote | " | All CSV sources | N/A | Yes | Standard text qualifier |
| Escaped Quote | "" | Fields containing quotes | N/A | Yes | Two consecutive double quotes |
| Newline in Field | \n | Address fields, notes | N/A | Yes | Must be inside quoted field |
| BOM Marker | U+FEFF | Windows Excel UTF-8 export | Stripped | N/A | Byte Order Mark removed on parse |
| CRLF | \r\n | Windows systems | Normalized | Yes | Converted to \n internally |
| LF | \n | Unix/Mac systems | Native | Yes | Standard internal line ending |
| CR | \r | Classic Mac OS | Normalized | No | Legacy, converted to \n |
| UTF-8 | Encoding | Modern systems | Default | Recommended | Tool reads as UTF-8 |
| Empty Field | ,, | Sparse datasets | N/A | Yes | Preserved as empty string |
| Trailing Delimiter | ,\n | Some exporters | Handled | Ambiguous | Creates empty last column |
| Header Row | First row | Most CSV files | Assumed | Optional | Toggle available in tool |