Download Caxton for Free · 7-day free trial of Caxton Pro, no credit card required · 8 MB · macOS 13.0+
The short answer
The best free way to split a large CSV on a Mac is qsv split, a command-line tool that writes a set number of records to each file and puts the header row at the top of every one. With nothing installed, an awk command in Terminal does the same for a file whose rows each sit on one line. Caxton, a native Mac editor for text and data files, has File ▸ Split File, which writes the parts into a folder you choose by line count, by size cut at line ends or by the values in one column, repeats the header in every part and adds a manifest of each part's lines and bytes.
Why split a CSV, and how large should each part be?
Three reasons cover most cases, and each one sets the size of a part differently.
A spreadsheet row limit. Microsoft's specifications page for Excel gives the "Total number of rows and columns on a worksheet" as "1,048,576 rows by 16,384 columns." The header takes one of those rows, so a part that carries the header can hold 1,048,575 rows of data at most, and 1,000,000 is the round number that leaves room. If Excel is the only reason for the split, CSV too big for Excel covers the other ways around the limit, and opening a huge CSV on a Mac covers reading the whole file without cutting it at all.
An upload limit. An import form or a mail server usually limits the size of a file, not the number of its rows, so the split is by size. Leave a margin under the limit, because a part that repeats the header is larger than its rows alone.
Sending a file in parts. When each recipient needs only their own rows, the useful cut is by the values in one column: one file per region, per customer or per month. A cut by row count gives parts that mean nothing on their own.
Whatever the reason, two things have to survive the cut. Every part needs the header row, or it is a list of values with no column names. And every row has to stay in one piece, which takes more care than it sounds when a cell holds a line break. Keep the original file until the parts have been checked.
How do I split a CSV in Terminal with the split command?
split ships with macOS. Apple's manual page describes a utility that "reads the given file and breaks it up into files of 1000 lines each (if no options are specified), leaving the file unchanged." The -l option sets the count, in the manual's words "Create split files line_count lines in length," and the last argument is a prefix for the names of the parts:
split -l 1000000 orders.csv orders-part-
The parts are named orders-part-aa, orders-part-ab and so on, with no .csv extension. Adding -d -a 3 numbers them orders-part-000, orders-part-001 instead. The command has two faults for a CSV, and both show on a small file. Here are the first lines of a file of ten orders, where the note on order 1003 holds a line break inside quotes:
order_id,customer,region,note
1001,Ana Ruiz,EU,first order
1002,Ben Okafor,US,gift wrap
1003,Chen Wei,EU,"leave at the door
ring twice"
1004,Dana Novak,EU,none
Split it every four lines and print the second part:
split -l 4 orders.csv orders-part-
cat orders-part-ab
ring twice"
1004,Dana Novak,EU,none
1005,Eli Hart,US,none
1006,"Fox, Gail",US,signed copy
The second part has no header, because the header is line one of the file and split copies it only into the part that holds line one. The part also opens with ring twice", the second half of a note whose first half ended the part before it. split counts lines, a row with a line break inside quotes is two lines, and the cut landed between them. Both parts are now broken at that row.
Two more facts from the manual page matter here. split -b cuts by size, described as "Create split files byte_count bytes in length," so the cut falls wherever that byte is, which is usually the middle of a row. And a name that is already taken is no protection: "By default, split will overwrite any existing output files."
How do I keep the header in every file?
awk also ships with macOS, and one command does what split -l does while putting the header at the top of every part:
awk -v n=1000000 'NR==1 {h=$0; next} (NR-2)%n==0 {if (f) close(f); f=sprintf("orders-part-%03d.csv", ++p); print h > f} {print > f}' orders.csv
It saves the first line as the header, starts a new file every n lines after it, and writes the header into each new file before the rows. The parts are named orders-part-001.csv, orders-part-002.csv and so on, and each holds the header and up to n lines. Change the number after n= and the file names to suit. For a clean export where every row sits on one line, this is all you need and there is nothing to install. It still counts lines, so a row with a line break inside quotes can be cut exactly as before.
How do I split a CSV without breaking rows that have line breaks inside quotes?
The CSV format allows a line break inside a cell as long as the cell is quoted. RFC 4180, the document that describes the format, puts it this way: "Fields containing line breaks (CRLF), double quotes, and commas should be enclosed in double-quotes." An address with two lines or a comment with a paragraph break is one cell in one row that happens to span two lines of the file, and a tool that counts lines cannot tell where such a row ends. Repair a malformed CSV shows how to find out whether a file has such rows, by comparing its line count with its record count.
With nothing installed, awk can follow the quotes. A line with an odd number of quote characters opens or closes a quoted cell, so this version starts a new part only when it is not inside one, and it counts rows instead of lines:
awk -v n=1000000 'NR==1 {h=$0; next} !q && c%n==0 {if (f) close(f); f=sprintf("orders-part-%03d.csv", ++p); print h > f} {print > f; if (gsub(/"/, "&") % 2) q=!q; if (!q) c++}' orders.csv
Run on the ten orders with n=3, it ends the first part with the whole two-line note and starts the next part at order 1004. The command trusts the file's quoting, so one stray quote character makes it count every later row wrongly. It also assumes the header is a single line.
The better free tool is one that parses the file as a CSV. qsv is a command-line toolkit for CSV files, open source under the MIT license and installed with brew install qsv. Its README states that "qsv follows the RFC 4180 CSV standard," and its split command works in records: the documentation gives --size as "The number of records to write into each chunk."
qsv split parts --size 1000000 orders.csv
The first argument is the output folder, and according to the documentation "If it does not exist, it will be created." The header needs no option: unless --no-headers is given, "the first row will appear in all chunks as the header row." Each file is named for the first record it holds, so the parts are 0.csv, 1000000.csv and so on, and --filename takes a template such as orders-{}.csv. For an upload limit, --kb-size splits by size in kilobytes, where "the size of each chunk will not exceed the desired size," and --chunks splits into a given number of files. For a CSV with multi-line cells that needs an exact number of rows in every part, qsv is the best choice on this page, because Split File in Caxton counts lines and not rows.
How do I split a CSV by the values in one column?
qsv has a separate command for it. Its documentation describes partition in one line, "Partitions the given CSV data into chunks based on the value of a column," and the example given there adapts directly:
qsv partition region . --filename "orders-{}.csv" orders.csv
That writes one file for each value of the region column into the current folder, orders-EU.csv and orders-US.csv for the ten orders, each with the header. The documentation describes the value in the name as "sanitized for shell safety," and it notes that on a file system that ignores case, with macOS APFS as its example, "the command will add a number suffix to the filename if the value is already in use."
With only the tools on the Mac, awk can build the file name from the column. Here the region is the third column:
awk -F, 'NR==1 {h=$0; next} {f="orders-" $3 ".csv"} !(f in seen) {seen[f]=1; print h > f; close(f)} {print >> f; close(f)}' orders.csv
It works on a clean file and goes wrong on a file with quoted cells, because -F, splits on every comma. On the ten orders, the row for "Fox, Gail" has a comma inside its quotes, so its third field is not the region, and the row lands alone in a file with a broken name. The second line of the two-line note lands in a file named orders-.csv. Use this command when no cell before the column can hold a comma and no cell holds a line break, and use qsv otherwise.
How do I split a CSV in Caxton?
Caxton has the split as a menu command with a form, for a file you already have open or a job you would rather not write a command for. File ▸ Split File… writes the open document as parts into a folder you choose and leaves the original as it is. Split File is Caxton Pro at any file size, because it writes new files. Every download starts with a 7-day free trial of Caxton Pro, no credit card required. On Caxton Free the command is refused with a banner that gives that reason beside a License… button, and the form does not open. Opening, viewing, searching and filtering the file stay Caxton Free at any size.
1. Open the file and let it finish reading
Drag the file onto Caxton or use File ▸ Open. A file whose name ends in .csv or .tsv opens in the grid, and the status bar shows Parsing CSV with a percentage while the table is read, then the number of rows and columns. Wait for that count before you split. Split File needs the whole file indexed, and until the index is complete the command is refused with a message asking you to try again. The header checkbox and the split by column value are offered only once the table has been parsed. This step is Caxton Free.
2. Choose File ▸ Split File… and pick the rule
The form has a Split by popup with four rules and a Value field for the number or the column.
Split File: the rule, its value, the header and the manifest, then the folder.
Line count per part writes that many lines to each part. In a table, a part whose last line falls inside a row runs on to the end of that row. The field starts at 100000 and accepts a number typed with commas, such as 1,000,000.
Size per part (MB), cut at line ends fills each part up to that many megabytes and ends it at the last line that fits, which in a table is the last whole row that fits. A megabyte here is 1,048,576 bytes. A single line or row longer than the limit becomes a part of its own.
Column value (CSV) writes one part for each distinct value of a column, which you name by its number counted from 1 or by its header. Parts come in the order the values first appear, and the rows inside each part keep the order they had in the file. The first 500 distinct values get a part each. Rows with any later value go together into one more part, named orders-other.csv for a file called orders, and a note about it appears in the status bar when the split ends.
Day (by timestamp) is for a log file whose timestamps Caxton recognized. It writes one part per calendar day, keeps a line without a timestamp with the line above it, and puts lines that come before the first timestamp into a part of their own with undated in its name.
3. Decide on the header and the manifest
Repeat the header row in every part is switched on when the table has a header row. Each part then starts with the header, which is added on top of the line count or the size you typed, so a part of 1,000,000 lines holds 1,000,001 with its header. With the box off, the header goes once, into the first part. Caxton treats the first row as the header unless CSV ▸ First Row Is Header is switched off, so clear the box for a file that has no header row.
Write a manifest naming the parts is also on to begin with. It adds a small text file named after the original, orders-parts.txt for a file called orders. Its first line gives the original's name and the number of parts, and each line after it gives one part's file name, its line count and its size in bytes, separated by tabs. For the ten orders split every four lines with the header repeated, the manifest reads:
Split of orders.csv: 3 parts
orders-part-001.csv 5 lines 136 bytes
orders-part-002.csv 5 lines 131 bytes
orders-part-003.csv 4 lines 101 bytes
That is the list to send along with the parts, so the person receiving them can check that nothing is missing.
4. Choose the folder
Choose Folder… opens a folder panel, and Split Here starts the split. It runs in the background as a job listed in View ▸ Operations (⌥⇧⌘J). When it ends, the status bar shows the number of parts and the folder, and the Finder opens with the first part selected. Parts by line count or by size are named orders-part-001.csv, orders-part-002.csv and so on. Parts by column value are named for the value, such as orders-EU.csv, and parts by day for the date, such as server-2026-11-10.log. The split reads the document as it stands in the window, so edits you have not saved yet are in the parts. Steps 2 to 4 are Caxton Pro.
Does Caxton keep rows with line breaks inside quotes whole?
Yes, under every rule, once the file has been read as a table. Lines are never cut: a part always ends at the end of a line. A line is not always a row, though, and in a table every rule also ends a part where a row ends. A row with a line break inside quotes is two lines, and both stay in the same part. The line count rule still counts lines, so a part whose last counted line falls inside such a row runs on to the end of that row and holds more lines than the number you typed. The header that is repeated is the whole first row, so a header cell with a line break stays whole as well.
Two conditions apply. The table has to be read to the end, which is the row count that step 1 waits for, and every quote in the file has to be closed. A file with a quote that never closes is split on its lines, as split and the first awk command would split it, and a row with a line break inside quotes can then be divided between two parts. The column value rule reads the parsed table in every case, where a quoted cell with a line break is one cell in one row, and it moves whole rows.
For a file with multi-line cells where every part must hold an exact number of rows, use qsv split or the quote-following awk command above, because both count rows. Inside Caxton the other route is CSV ▸ Remove Embedded Newlines…, which replaces every line break inside a quoted cell with a space so that each row is one line and the line count is the row count. That changes the data, ⌘Z restores the previous text, and applying it is Caxton Pro.
What happens when a part's name is already taken?
Before it writes anything, Caxton checks the folder for every name it is about to use, the manifest's included. If one of them exists, an alert asks whether to replace it. The alert names the file, or for several files counts them and lists the first five. Cancel stops there, and nothing is written. Replace lets the split overwrite those files.
Two parts can also want the same name in a split by column value, because a value is made safe for a file name first. Letters and digits of any script are kept, accented letters included, and so are the dot, the dash and the underscore. Every other character becomes an underscore. The value is cut at 60 characters at most, and shorter when the whole name would not fit the length the disk allows. An empty value, or one with none of the kept characters, gives a part named orders-blank.csv. When two values arrive at the same name, or at names the disk treats as one, such as Apple and apple, the second part gets -2 added, the third -3 and so on. The values A/B and A:B become orders-A_B.csv and orders-A_B-2.csv. No part can take the manifest's name or the name of the other part.
What happens if I cancel a split?
Open View ▸ Operations, select the job named for the file and click Cancel. If the split was still working out the parts, nothing has been written, and a banner confirms it. If it was already writing, it stops and removes every part it had written, the unfinished one included, and the banner counts them, for example that the 3 parts written were removed. The folder is left as it was, because Caxton writes the parts aside and moves them into the folder only when every one of them is whole. A split that fails part way, on a full disk for instance, cleans up the same way.
A file you agreed to replace is therefore still there after a cancelled or failed split, with its earlier contents, because it is replaced only at the end. If the move into the folder itself fails part way, Caxton takes the new parts back out and puts back every file they had replaced. A part that cannot be removed is named in the banner. When a file cannot be put back, the banner names the place where that file is kept and stays on screen. The document you are splitting is never changed by any of this.
Which approach fits which job?
| Job | Free in Terminal | In Caxton |
|---|---|---|
| Every row on one line, cut by row count | The awk command that repeats the header | Split by Line count per part |
| Cells with line breaks, cut by row count | qsv split, or the quote-following awk command | Split by Line count per part keeps every row whole, and it counts lines, so use qsv when the number of rows must be exact |
| Parts that fit an upload limit | qsv split --kb-size | Split by Size per part (MB), cut at line ends |
| One file per value of a column | qsv partition | Split by Column value (CSV) |
| A list of the parts with their line counts | wc -l orders-part-*.csv | The manifest written beside the parts |
Open the file, choose File ▸ Split File, and check the manifest against the parts before you send them.
Download Caxton for Free7-day free trial of Caxton Pro, every feature, no credit card required. After it, Caxton Free keeps opening, searching and filtering at any size, and you can edit and save files up to 10 MB as text.
Frequently asked questions
How do I keep the header in every file?
The split command copies the header only into the first part, because it treats the header as one more line. An awk command can save the first line and write it at the top of every new part, and qsv split repeats the header in every file unless you tell it not to. In Caxton, File ▸ Split File has a checkbox named Repeat the header row in every part, which is on for a table with a header row, and when it is off the header goes once into the first part.
How do I split a CSV by the values in one column?
The qsv tool has a partition command that writes one file for each distinct value of the column you name, with the header in every file. An awk command in Terminal can do it on a clean file by building the file name from the column, but it splits on every comma, so a comma inside quotes earlier in the row sends that row to the wrong file. In Caxton, choose File ▸ Split File, set Split by to Column value (CSV) and type the column's number or its header name. Each distinct value gets its own part, up to 500 values, and rows with any further value go into one part named other.
Will splitting break rows with line breaks inside quotes?
It can, whenever the tool counts lines instead of rows. The split command and a simple awk line counter end a part after a set number of lines, so a row with a line break inside quotes can be divided between two files. qsv split counts records and keeps such a row whole. In Caxton, Split File ends every part of a table where a row ends, under every rule, so a row that spans two lines stays in one part. A split by line count still counts lines, and a part whose last line falls inside a row runs on to the end of that row.
How many rows should each part have to open in Excel?
Microsoft gives the size of an Excel worksheet as 1,048,576 rows by 16,384 columns, and the header takes one of those rows. A part that carries the header can hold at most 1,048,575 rows of data, and 1,000,000 per part is the round number that leaves room. In Caxton's Split File, type 1,000,000 as the line count and keep Repeat the header row in every part switched on.
Sources
- Caxton manual: Editing, Split and combine files
- Caxton manual: License, what is Caxton Free and what is Caxton Pro
- Caxton manual: the CSV workbench, Remove Embedded Newlines and First Row Is Header
- Microsoft: Excel specifications and limits
- qsv documentation: split
- qsv documentation: partition
- qsv README: installation, the RFC 4180 section and the license
- RFC 4180: Common Format and MIME Type for Comma-Separated Values (CSV) Files
- Apple's manual pages on macOS:
man splitandman awk, read with the shipped tools in Terminal