· CSV.ink Team

How to Merge Multiple CSV Files into One

Stacking CSVs is easy when every file has the same columns. When headers drift, you need a union of column names and empty cells for gaps.

Exports from different months, regions or systems often land as separate CSVs. Before analysis or a single upload, you want one file. The merge is simple if headers match; it needs a rule when they do not.

Same headers — concatenate rows

Keep the header from the first file. Append every following file’s data rows, skipping their header lines. That is ordinary concatenation.

orders_jan.csv + orders_feb.csv → orders_h1.csv

Different headers — union of columns

January has coupon_code, February does not; February added shipping_region. A practical merge builds the set of all column names (trimmed), writes that as the header, then places each row’s values under matching names and leaves the rest blank.

Match columns by name, not by position. If one file swapped two columns, position-based merges silently scramble data.

Merge CSV files online →

Add a source column when you need an audit trail

After a merge it is hard to see which file a weird row came from. Optional column like source_file with values jan.csv / feb.csv saves time when reconciling totals.

Watch for these traps

  • Encoding: merge UTF-8 with UTF-8. Mixing GBK and UTF-8 without converting first produces mojibake in half the rows.
  • Delimiter: do not mix comma and semicolon files in one pass.
  • Duplicate rows: merging does not dedupe. Remove duplicates afterward if the same order can appear in two exports.

Split again if a tool rejects the merged size →

Merged files get big fast. If the destination has a size cap, split after cleaning rather than uploading a single giant CSV.

Example: three regional exports

Suppose eu.csv has columns id,email,country and us.csv has id,email,state. After a name-based union the header becomes id,email,country,state. European rows leave state blank; US rows leave country blank unless you also mapped country=US yourself. That sparse table is still valid CSV and loads cleanly into most tools.

If a later step requires every row to have country, fill defaults in a second pass — do not invent data silently inside the merge.

Outils associés

← Tous les articles

Autres articles