How to Merge Multiple CSV Files Without a Script
Last updated 19 August 2026 · about 4 minutes to read
Why cat and copy break when column orders differ, what merging by header name does instead, and what to check before you combine exports.
Merging CSVs looks like concatenation and is not. Concatenation joins the bytes. Merging has to join the columns, and the columns are named in a row that concatenation repeats in the middle of the file.
Why the obvious approaches break
On a Unix shell, cat *.csv > all.csv produces a file with a header row in the middle of it, once per input. On Windows, copy *.csv all.csv does the same. Both then break the moment two files order their columns differently: the second file's rows land under the first file's headers, so a name column fills with dates and nobody notices until much later.
Skipping the extra headers with tail -n +2 fixes the repeated rows and not the ordering problem, which is the one that costs you.
Merging by name
The reliable approach is to read the header of each file, union the names across all of them, and place every row under the header it actually had. A file with columns id, name, total merges correctly with one that has name, total, id, because position is never used.
Columns that appear in some files and not others become columns that are empty for the rows from the files that lacked them. That is more useful than refusing to merge, and more honest than silently dropping the column, because the gap is visible in the result.
What to check first
- Do the header names mean the same thing in every file? Two exports can both have a date column where one is the order date and one is the ship date. No tool can detect that, and merging them produces a file that is wrong in a way nobody will find.
- Is one file's header spelled differently? Customer ID and customer_id are two columns as far as any merge is concerned. Rename them to match before you start.
- Do the files use the same encoding? A UTF-8 file and a Windows-1252 file merged together produce one file with two encodings in it, which is not a thing that can be read correctly.
- Should duplicates be removed? Overlapping date ranges in two exports are the usual source. Merge first, look at the row count, then deduplicate if the number is higher than it should be.
Adding a source column
If it matters which file a row came from, add a column for it before merging. Once the rows are combined there is no way to work it out, and the question comes up more often than people expect: when a total is wrong, the first thing you want to know is which export it came from.
When to write a script instead
If this is a recurring job rather than a one-off, script it. A tool is right for the file you have today and wrong for the file you will have every Monday. The point where it pays to script is roughly the third time you do it by hand.