CSV Column Inserter
Insert a new column into any CSV file at a specific position. Fill with static values, row numbers, or computed data. Download instantly.
About
Manually editing CSV files in a text editor to add a column is error-prone. A misplaced comma inside a quoted field corrupts every subsequent row. This tool implements a full RFC 4180-compliant parser that correctly handles quoted fields, embedded delimiters, escaped double-quotes (""), and newlines within cell values. It inserts a new column at any position k where 0 ≤ k ≤ n (total existing columns), then re-serializes the data preserving the original quoting rules. The tool auto-detects delimiters by frequency analysis across the first 5 lines, scoring candidates: comma, semicolon, tab, and pipe.
Fill modes include static text, incremental row index (starting from 1), or leaving cells empty for later population. For files exceeding 1 MB, processing offloads to a Web Worker to keep the UI responsive. Note: this tool operates entirely in-browser. No data leaves your machine. Maximum practical file size depends on available browser memory, typically around 100 - 200 MB on modern devices.
Formulas
The column insertion operates on a zero-indexed position. Given a row represented as an ordered tuple of n fields:
Inserting a new field v at position k yields:
Where k ∈ {0, 1, …, n}. The resulting row length becomes n + 1. For row-index fill mode, the value v for row i (data rows, excluding header if present) is:
Delimiter auto-detection scores each candidate d by computing the standard deviation σ of occurrence counts across sampled lines. The candidate with the lowest non-zero σ and highest mean count wins. A field requires quoting in the output if it contains the delimiter character, a double-quote, or a newline.
Reference Data
| Delimiter | Symbol | Common Use | Auto-Detect Key | RFC Standard |
|---|---|---|---|---|
| Comma | , | Most CSV files (US/UK locale) | Highest frequency non-quoted | RFC 4180 |
| Semicolon | ; | European CSV (Excel EU export) | Common when comma is decimal separator | No formal RFC |
| Tab | \t | TSV files, database exports | Consistent count per line | IANA text/tab-separated-values |
| Pipe | | | Legacy systems, mainframe exports | Rare in natural text | No formal RFC |
| Quoted Field | "..." | Fields containing delimiters or newlines | Starts and ends with double-quote | RFC 4180 §2.6 |
| Escaped Quote | "" | Literal double-quote inside quoted field | Two consecutive double-quotes | RFC 4180 §2.7 |
| CRLF Line End | \r\n | Windows-origin files | Normalized to \n during parse | RFC 4180 §2.1 |
| LF Line End | \n | Unix/macOS-origin files | Default line break | Common practice |
| UTF-8 BOM | \uFEFF | Excel UTF-8 exports | Stripped during parse | Unicode §2.6 |
| Header Row | - | First row as column names | User toggle | RFC 4180 §2.3 (optional) |
| Empty Field | ,, | Missing data / NULL values | Zero-length between delimiters | RFC 4180 §2.5 |
| Trailing Delimiter | ,\n | Some legacy exporters | Creates phantom empty column | Not standard (common bug) |