CSV Column Prepender
Prepend a new column to your CSV file instantly. Add custom values, row numbers, or static text as the first column in any CSV data.
About
Inserting a column at position zero in a CSV file sounds trivial until your data contains quoted fields with embedded commas, newlines inside cells, or escaped double-quotes. A naive find-and-replace corrupts the file. This tool implements a full RFC 4180 parser that tokenizes each record correctly before inserting the new column value at the specified index. It handles edge cases most spreadsheet exports produce: fields wrapped in DQUOTE characters, CRLF sequences inside quoted text, and mixed delimiters. All processing runs client-side in your browser. No data leaves your machine.
The prepend value supports three modes: a static string applied uniformly, an auto-incrementing row index (starting from 0 or 1), or a pattern with a {n} placeholder for sequential numbering. The tool auto-detects your delimiter by analyzing character frequency across the first 5 lines. Accuracy depends on consistent formatting. If your source file uses mixed delimiters, results will be unreliable. Fix the source first.
Formulas
The delimiter auto-detection algorithm scores each candidate delimiter d by computing a consistency metric across the first N lines:
Where σd is the standard deviation of delimiter d count per line (lower is better - consistent column count), and d is the mean occurrence count. The delimiter with the highest score wins. A score of 0 means the character never appeared.
Column prepend operation per record Ri:
Where newValue(i) resolves to the static string, row index, or pattern result depending on mode. If the value itself contains the active delimiter or quotes, it is automatically wrapped in DQUOTE per RFC 4180 before serialization.
Reference Data
| Delimiter | Common Name | Character Code | Typical Source | Auto-Detected |
|---|---|---|---|---|
| , | Comma | U+002C | Excel (EN), Google Sheets | Yes |
| ; | Semicolon | U+003B | Excel (EU locales) | Yes |
| \t | Tab (TSV) | U+0009 | Database exports, Unix tools | Yes |
| | | Pipe | U+007C | Legacy mainframe systems | Yes |
| : | Colon | U+003A | /etc/passwd, config files | No |
| ^ | Caret | U+005E | SAS transport files | No |
| ~ | Tilde | U+007E | EDI / X12 formats | No |
| RFC 4180 Quoting Rules | ||||
| Field contains delimiter | Wrap entire field in double quotes: "hello, world" | |||
| Field contains double quote | Escape with double-double quote: "say ""hi""" | |||
| Field contains newline | Wrap in double quotes; parser must track open/close state | |||
| Leading/trailing whitespace | Not trimmed per RFC 4180; preserved as-is | |||
| Empty field | Two consecutive delimiters: a,,c → 3 fields | |||
| BOM marker (U+FEFF) | Stripped automatically by this tool if present at byte 0 | |||