How do you merge CSV files on a Mac?
By Kayabyte · Last updated 2 November 2026
To merge CSV files on a Mac, join them in Terminal so the header appears only once: awk 'FNR==1 && NR!=1 {next} {print}' *.csv > ../merged.csv keeps the first file’s header row and drops it from every other file. That is fast for files with identical columns, and it breaks on different columns, mixed encodings and CSVs that do not end with a line break. Gridhand stacks the rows by header text and writes a .xlsx; Convert can then write that sheet back out as a CSV. If you want an Excel workbook with a tab per CSV instead, see combine CSV files into one Excel workbook.
Method 1: Terminal with awk
Open Terminal, go to the folder with the CSVs (cd ~/Documents/csvs) and run:
awk 'FNR==1 && NR!=1 {next} {print}' *.csv > ../merged.csv
The output goes one folder up so that it is not read as an input. FNR is the line number inside the current file and NR the number over all files, so line 1 of every file except the first is skipped. awk also adds a line break after a last line that lacks one, which avoids two rows being glued together.
Method 2: cat or tail with the header written once
head -n 1 first.csv > ../merged.csv writes the header once. Then for f in *.csv; do tail -n +2 "$f" >> ../merged.csv; done appends every file without its first line (tail -n +2 starts at line 2). Here a file without a final line break does glue its last row to the next file’s first row, so check the end of each file or use awk.
Pitfalls
- Repeated headers: plain
cat *.csv > all.csvcopies every header into the middle of your data. - Missing trailing newline: the last row of one file joins the first row of the next.
- Different columns or column order: line-based tools stack by position, so values land under the wrong header. Check that every file starts with the same header line, for example
for f in *.csv; do head -n 1 "$f"; done | sort | uniq -c. - Encodings: a Windows-1252 file mixed with UTF-8 files shows garbage characters.
iconv -f WINDOWS-1252 -t UTF-8 in.csv > out.csvconverts one file. - Byte order mark (BOM):
head -c 3 file.csv | xxdshowingefbbbfmeans a BOM. In the middle of merged data it becomes a stray character, andtail -c +4 file.csvremoves it from one file. - Windows line endings: carriage returns (
\r) can survive in the last column.tr -d '\r'removes them. - Quoted line breaks: a field that contains a newline can confuse tools that read line by line.
- Opening in Excel: double-clicking a UTF-8 CSV without a BOM can show broken accents, and Excel can turn 00123 into 123. Use Data, Get Data, From Text/CSV (menu names vary by Excel version) to pick the file origin and set that column to text.
Manual route in Excel or Numbers
Open each CSV, copy its rows without the header and paste them under the first file’s rows. Numbers works the same way: open each CSV, copy the rows and paste them under each other. This is fine for 3 files and slow for 30. For the Excel side of the job, see combine Excel files into one sheet.
With Gridhand
Gridhand reads CSV, TSV and text files in Convert, with encoding (BOM, UTF-8, UTF-16, Windows-1252) and delimiter (comma, semicolon, tab, pipe) detected, and IDs with leading zeros kept as text. Merge works on workbooks, so the route is two steps: Convert the CSVs to .xlsx, then Merge them “Into one sheet (stack the rows)”. Merge finds each header row, matches columns by header text ignoring case and spaces, keeps columns that only some files have, and can add the source file as a column. The output is an .xlsx file. Originals are never modified.
To get a CSV back, add the stacked .xlsx to Convert in “XLSX to CSV” mode: it writes one CSV per sheet, with the delimiter, encoding and line endings you choose. Dates are written as yyyy-mm-dd and formulas as their saved result.
Steps with Gridhand
- Drop the CSV files into Gridhand, choose Convert, “CSV, TSV or text to XLSX”, check the encoding and delimiter in the preview, and run it with one .xlsx per CSV.
- Add the new .xlsx files to Merge and choose “Into one sheet (stack the rows)”, with the source file option ticked if you want to see where each row came from.
- Check the preview, choose an output folder and press Run.
- For a CSV, add the merged .xlsx to Convert, choose “XLSX to CSV”, set the delimiter and encoding, and run it.
Free for up to 3 input files per run, so a free run covers 3 CSVs at a time, and the Merge step has the same limit on the converted files; Gridhand Pro is USD 49 once. Download Gridhand · Pricing
Questions
Can Gridhand merge CSV files directly? Not in one step: Convert makes .xlsx files from the CSVs and Merge stacks those. Convert can write the result back to CSV.
Do the CSVs need the same columns? In Gridhand, no. Columns are matched by header text and extra columns are kept. With awk or cat they must match.
Does the result come out as CSV or XLSX? Merge writes .xlsx. Convert’s “XLSX to CSV” mode writes one CSV per sheet, so a stacked single sheet becomes one CSV.
How do I keep the header only once in Terminal? Use awk 'FNR==1 && NR!=1 {next} {print}' *.csv > ../merged.csv, or write the header with head and append the rest with tail -n +2.
Related guides
- Combine CSV files into one Excel workbook
- Convert XLSX to CSV on a Mac
- Batch convert CSV to XLSX on a Mac
Microsoft and Excel are trademarks of the Microsoft group of companies. Gridhand is made by Kayabyte and is not affiliated with or endorsed by Microsoft.
More guides
- Is there an ASAP Utilities for Mac, and what can you use instead?
- How do you clean data in many Excel files at once on a Mac?
- How do you compare two Excel files on a Mac?
- How do you find and replace in multiple Excel files on a Mac?
- Gridhand vs XLclick vs XLWizard: which Excel tool for Mac?
- Is there a Kutools for Mac, and what are the alternatives for Mac?
- How do you merge Excel files on a Mac?
- Can you use Power Query on a Mac to merge Excel files?
- How do you remove duplicates from two or more Excel files?
- How do you split Excel data into one file per customer, region or month on a Mac?
- How do you split an Excel workbook into one file per sheet, or every N rows, on a Mac?
- How do you do a VLOOKUP between two Excel files on a Mac?