How to merge CSV files into one
By the Analistable team · Updated · 3 min read
To merge CSV files with the same columns, keep the header row from the first file and append only the data rows from the rest. In Excel, use Data → Get Data → From File → From Folder → Combine. On Mac or Linux, awk 'FNR==1 && NR!=1 {next} {print}' *.csv > ../merged.csv does it in one line. To skip both, drop the files into our free CSV combiner.
Methods compared
| Method | Handles headers | Different columns | Skill |
|---|---|---|---|
| Excel Power Query (From Folder) | Yes | Yes (by name) | Low |
| Windows `copy *.csv` | No — repeats headers | No | Low |
| Mac/Linux `awk` | Yes | No | Medium |
| Python pandas | Yes | Yes (by name) | Medium |
| Browser combiner | Yes | Yes (by name) | None |
In Excel with Power Query
Put the CSV files in one folder. Choose Data → Get Data → From File → From Folder, select the folder, then Combine & Transform Data. Power Query promotes the header of each file and stacks the rows, adding a Source.Name column. Click Close & Load. Details and fixes for delimiter and encoding problems: combining CSV files in Excel.
From the command line
On Windows, copy *.csv merged.csv in Command Prompt concatenates the files byte for byte, so every file's header row ends up in the middle of the data. Delete those rows afterwards, or use PowerShell:
Get-ChildItem *.csv | Import-Csv | Export-Csv ..\merged.csv -NoTypeInformation
On Mac or Linux, awk skips the first line of every file except the first. Write the output to another folder so it doesn't include itself. Mac steps: combining CSV files on a Mac.
In Python
pd.concat([pd.read_csv(f) for f in glob.glob('data/*.csv')], ignore_index=True).to_csv('merged.csv', index=False) reads every file and aligns columns by name. See merging data in pandas.
Problems that are specific to CSV
- Delimiters: some exports use semicolons (common in European locales) or tabs. Set the delimiter explicitly.
- Encoding: accented characters turn into symbols when a UTF-8 file is read as ANSI. Choose UTF-8 (65001) as the file origin.
- Leading zeros: Excel turns 00123 into 123 when it opens a CSV directly. Import through Power Query and set the column to Text.
- Line breaks inside quoted fields break naive line-based tools such as
cat. Use a CSV-aware method for exports that contain notes or addresses.
Merging online
Most online CSV mergers upload your files to a server. The Analistable CSV merger runs in your browser instead: headers are matched by name, a source column is added, and you download one CSV.
Worked example
| source | order_id | date | amount |
|---|---|---|---|
| orders_2026-10-01.csv | A-1001 | 2026-10-01 | 42.5 |
| orders_2026-10-01.csv | A-1002 | 2026-10-01 | 18 |
| orders_2026-10-02.csv | A-1003 | 2026-10-02 | 64 |
| orders_2026-10-03.csv | A-1004 | 2026-10-03 | 27.9 |
One header row, one source column, rows in file order. If the file names carry the date, as here, you can also turn the source column into a proper date column for sorting and grouping.
Check the merged file
- Row count: the merged file should have the sum of each file's data rows plus one header. On Mac or Linux,
wc -l *.csvlists line counts per file. - Header rows in the data: filter the first column for its own header text; any hit means a header was copied as data.
- Column count: a row with more or fewer fields than the header usually means an unquoted comma inside a value.
- Encoding: search for “Ô — it's the tell-tale sign of UTF-8 text read as ANSI.
Which method should you choose?
- Same columns, many files, you're comfortable with Terminal → awk or PowerShell.
- Files from different systems (delimiters, encodings, extra columns) → Power Query or pandas.
- You merge the same exports every week → Power Query From Folder with Refresh.
- One-off merge, no installation, sensitive data → a browser-local combiner.
Every guide in this topic
- How to combine CSV files in Excel
Combine multiple CSV files into one Excel sheet or workbook with Power Query From Folder, and fix delimiter, encoding, leading-zero and date problems.
- How to combine CSV files into one on a Mac
Merge CSV files on a Mac with one Terminal command that keeps a single header row, or with Excel's Power Query, or in the browser. Copy-ready commands.
- The best free ways to merge CSV files
Free ways to merge CSV files compared: command line, Excel Power Query, Python, csvkit, Google Sheets and browser tools — headers, columns, size and privacy.
Frequently asked questions
- How do I merge multiple CSV files into one?
- Use Excel's Data → Get Data → From Folder → Combine, a one-line command (awk on Mac/Linux, PowerShell on Windows), pandas in Python, or a browser combiner that keeps a single header row.
- Why does my merged CSV have header rows in the middle?
- Simple concatenation (copy *.csv or cat) copies each file's header. Use a method that skips the first line of every file after the first.
- Can I merge CSV files with different columns?
- Yes, if the method matches columns by header name: Power Query, pandas and the Analistable combiner do. Command-line concatenation does not.
- Is there a limit to how many CSV files I can merge?
- Not in the methods themselves, but Excel sheets hold at most 1,048,576 rows. For more, keep the result as CSV or load it into a database.