Analistable

How to combine CSV files into one on a Mac

By the Analistable team · Updated · 5 min read

Open Terminal, go to the folder with cd, and run awk 'FNR==1 && NR!=1 {next} {print}' *.csv > ../combined.csv. It keeps the header of the first file, skips the header of every other file, and writes the result to the parent folder so the output isn't read as an input. Excel for Mac's Power Query (From Folder) and browser tools also work.

Part of our guide: How to merge CSV files into one

Terminal: one command

  1. Open Terminal (Applications → Utilities).
  2. Type cd (with a space), drag the CSV folder from Finder into the window, and press Enter.
  3. Run the command below.
awk 'FNR==1 && NR!=1 {next} {print}' *.csv > ../combined.csv
  • FNR is the line number within the current file and NR the line number overall, so FNR==1 && NR!=1 matches the first line of every file except the first one.
  • {next} skips that line; {print} prints every other line.
  • > ../combined.csv writes the result one folder up. If you write into the same folder, a second run would include combined.csv itself.

Files are combined in alphabetical order of their names. awk also adds a missing newline at the end of a file, which plain cat doesn't — with cat, the last row of one file can end up glued to the first row of the next.

Add the file name to each row

awk 'FNR==1 { if (NR==1) print "source," $0; next } { print FILENAME "," $0 }' *.csv > ../combined.csv

Every data row now starts with the file it came from, and the header gets a matching “source” column.

Limits of the command-line approach

When awk isn't enough
SituationBetter option
Files have different or reordered columnsPower Query or a tool that matches headers by name
Quoted fields contain line breaksA CSV-aware tool (Python, csvkit, Power Query)
Files use different delimiters or encodingsPower Query, where you set both per source

Excel for Mac

Microsoft 365 for Mac includes Power Query's From Folder connector: Data → Get Data (Power Query) → From Folder, then combine. The steps and fixes are the same as on Windows — see combining CSV files in Excel. For Excel workbooks rather than CSVs, see combining Excel files on a Mac.

In the browser

The Analistable CSV combiner works in Safari and Chrome. It matches columns by header name, adds a source column and downloads one CSV, and the files stay on your Mac.

Numbers can open CSVs but has no merge feature; copy-pasting between documents is the only built-in option.

Check the result in Terminal

Before opening the combined file, confirm nothing was lost:

wc -l *.csv            # lines per input file, plus a total
wc -l ../combined.csv   # lines in the output
head -3 ../combined.csv # header and first rows
grep -c '^date,' ../combined.csv   # should be 1 if your header starts with "date,"

With three files of 101, 81 and 121 lines (each a header plus 100, 80 and 120 data rows), the output should have 1 header + 300 data rows = 301 lines. Line counts can be off by one when a file has no newline at the end, which wc -l doesn't count. Quoted fields that contain line breaks also inflate the count, so treat it as a sanity check rather than an exact row count.

Control the order and choose files

  • Only certain files: replace *.csv with a pattern such as sales_2026-*.csv.
  • Files in subfolders: find . -name '*.csv' -print0 | sort -z | xargs -0 awk 'FNR==1 && NR!=1 {next} {print}' > ../combined.csv.
  • Chronological order: name files with ISO dates (2026-09 rather than Sep-2026) so the alphabetical order the shell uses is also the date order.
  • Spaces in file names are fine with *.csv; the shell passes each name intact.

Common errors

Terminal problems and fixes
Message or symptomCauseFix
no such file or directoryYou are not in the CSV folderRun `pwd` and `ls` to check, then `cd` again
Output contains strange characters at the startA UTF-8 byte order mark in each fileOpen in Excel, which handles it, or strip it with a CSV tool
All rows on one line in ExcelFiles use old Mac (CR) line endingsConvert with `tr '\r' '\n'` before combining
combined.csv keeps growingOutput written into the input folderWrite to `../combined.csv` as shown

Opening the result in Numbers or Excel

Double-clicking a CSV opens it in your default app, which may reformat values: long IDs can become scientific notation and leading zeros disappear. In Excel for Mac, use File → Import (or Data → From Text) instead, choose the delimiter and set ID columns to Text. Numbers keeps values as typed more often but has its own row and column limits for very large files, so check the row count after opening.

Repeat it every month

Save the command as a small script so next month is one double-click:

#!/bin/bash
cd "$(dirname "$0")"
awk 'FNR==1 && NR!=1 {next} {print}' exports/*.csv > combined.csv
echo "Combined $(($(wc -l < combined.csv) - 1)) data rows"

Save it as combine.command next to an exports folder, run chmod +x combine.command once, and double-click it in Finder. macOS may ask you to confirm the first time you run it.

Frequently asked questions

How do I merge CSV files on a Mac without repeating headers?
In Terminal, run awk 'FNR==1 && NR!=1 {next} {print}' *.csv > ../combined.csv from the folder that contains the files.
Why does cat *.csv > combined.csv give me extra header rows?
cat copies every file completely, including each file's header line. Use the awk command, which skips the first line of every file after the first.
Can Excel for Mac combine CSV files?
Yes. Microsoft 365 for Mac has Power Query's From Folder connector, which combines every CSV in a folder.
Will the Terminal command work on Linux too?
Yes. awk, wc and find behave the same way for these commands on Linux, so the same lines work in any Linux terminal.
How do I combine CSV files that use semicolons instead of commas?
The awk command works unchanged because it copies whole lines. Only the source-column version needs editing: replace the comma after FILENAME with a semicolon so the new column uses the same delimiter.

Related guides