Data · 25 tools · nothing uploads

Reorder / insert CSV columns

Reorder (and drop) a CSV's columns by name, and optionally insert one new column with a constant value at a given position. Quote-aware. A record with a quoted field containing a literal newline stays one record. Runs entirely on your device.

Input

Options

live

Reorder / insert CSV columns rewrites a CSV's columns into the order you list, dropping any name you leave out. insertName adds one more column holding insertValue in every row, placed at the zero-based insertAt or appended when that is blank. Leaving both order and insertName blank is refused, since the output would be a copy of your file.

Questions

How do I reorder or drop columns?

Put the header names you want, comma separated, in the order option. That order becomes the new column order, and any column you leave out is dropped. Leave order blank to keep the layout as it is. If a name is not in the header the tool refuses with "column(s) not found in the header" and prints the header it did find, so you can check the spelling.

How do I add a new column?

Set insertName to the column name and insertValue to the constant that goes in every row. insertAt is a zero based position, so 0 puts it first; leave it blank to append at the end. Setting a value without a name is refused with "insertValue is set but insertName is blank", since the column would have nowhere to live in the header.

Why did it say there is nothing to do?

Because both order and insertName were blank, which would produce an exact copy of your file. The tool refuses with "give either order or insertName" rather than spending the run writing your input back out. Fill in at least one of them.

Will it break rows that contain commas or newlines?

No. The parser tracks quote state across the whole file, so a quoted field holding a comma or a literal newline stays one field in one record. The output is re-quoted the same way, so a multi-line cell survives the round trip. That is the difference between reading records and splitting on line breaks.

What if some rows have fewer cells than the header?

Missing cells are filled with empty strings as the columns are rearranged, so short rows come out the right width instead of shifting the data. To see which rows were ragged before you change anything, run Find incomplete CSV records first.

What is the output file called?

Your file name with -columns.csv on the end, so contacts.csv becomes contacts-columns.csv. It is written on your device and never uploaded, and the entire file is held in memory while it runs, which is what limits how large a CSV you can put through it.

Related Data tools

1→1Map CSV column namesRename a CSV's header to a new schema ("old=new" pairs), and optionally drop every column that isn't named in the mapping. Column order and data are otherwise untouched. Quote-aware. A record with a quoted field containing a literal newline stays one record.Takes one file1→1Change CSV separatorRe-delimit a CSV (comma, semicolon, tab or pipe), auto-detecting the current separator when not told what it is. Quote-aware. A record with a quoted field containing a literal newline (including in the header) stays one record.Takes one file1→1Transpose CSVSwap a CSV's rows and columns. Column 1 becomes row 1, and so on. A ragged row (fewer cells than the widest row) is padded with empty cells rather than refused. Quote-aware. A record with a quoted field containing a literal newline stays one record, not two.Takes one file1→1Split CSV into partsCut a CSV into several smaller files of N data rows each, repeating the header in every part. Quote-aware: a record with a quoted field containing a literal newline stays one record.Takes one filen→1Merge CSV filesConcatenate several CSVs with the same header into one file, in the order given. Quote-aware. A record with a quoted field containing a literal newline stays one record.Combines the files you drop1→1Remove duplicate CSV rowsStrip repeated rows from a CSV. Compares whole records, not physical lines, so a quoted field containing a newline is one record and stays one record.Takes one file1→1Find incomplete CSV recordsReport every record whose cell count doesn't match the header: too few cells (a truncated record) or too many (an unescaped comma). Read-only: nothing is changed. Quote-aware, so a record with a quoted field containing a literal newline still counts as one record with the right cell count.Takes one file1→1CSV to tableConvert a CSV to markdown, HTML, LaTeX, SQL INSERT statements, JSON, YAML, or Jira table markup. The first row is always the header (object keys for JSON); every format quotes its own special characters.Takes one file