Data tools

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.

Runs on your device. The file is never uploaded.

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.

Input

Options

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