Handling large datasets is an essential part of data analysis and processing. However, working with large CSV files can often be challenging, especially when importing or manipulating the data.
One common solution to this problem is to split the large CSV file into multiple smaller files that are easier to manage, especially helpful if you have limited storage space or need to share the data with others.
This blog post will explore how to split a large CSV file into multiple smaller files using a Mac computer.
How to Split a Large CSV File into Multiple Smaller Files Using Mac?
Here are the three (3) ways to do so.
Method 1. Using Mac Terminal
Using the Mac terminal is an efficient way to accomplish this task.
Split CSV file using Terminal
Here’s a step-by-step guide on how to do it:
- Open the Mac Terminal
Use the Spotlight Search to find “Terminal” or click on the “Finder” icon on your dock, navigate to “Applications,” then “Utilities,” and finally, “Terminal.”
- Navigate to the folder containing the large CSV file.
For example, if your CSV file is on your desktop, you can navigate to it by typing “cd ~/Desktop” and pressing <Enter> on your keyboard.
cd ~/Desktop
- Split the CSV file into smaller files.
Use the <split> command to divide the CSV file into smaller files. The basic syntax for the <split> command is as follows:
split -l [number of lines per file] [name of large file] [prefix for new files]
Here’s an example command:
split -l 5000 largefile.csv smallerfile-
This command will split the large CSV file into smaller files that contain 5000 lines each. The new files will be named “smallerfile-aa,” “smallerfile-ab,” “smallerfile-ac,” and so on.
That’s it! Using the Mac terminal, you’ve successfully split a large CSV file into multiple smaller files. This method is incredibly efficient and can save you a lot of time and storage space.
Merge CSV files using Terminal
After you’ve split a large CSV file into multiple smaller files, you may need to merge them back together for further analysis or processing.
Here’s how you can merge the smaller files back into one larger CSV file using the Mac terminal:
- Open the Mac Terminal
- Navigate to the directory containing the smaller files.
- Merge the smaller files
To merge the smaller files back into one larger CSV file, use the <cat> command with a wildcard character (*). The basic syntax for the <cat> command is as follows:
cat [prefix for smaller files]* > [name of larger file].csv
Here’s an example command:
cat smallerfile-* > mergedfile.csv
This command will merge all the files in the directory that start with “smallerfile-” into one larger CSV file named “mergedfile.csv.”
You’ve successfully merged the smaller files back into one larger CSV file using the Mac terminal.
Method 2. Using MacUncle
MacUncle CSV Splitter is a software tool designed specifically for Mac computers to split large CSV files into smaller, more manageable files.
You need to download and install this macOS application.
Here are the customizable splitting options available in the tool;
Split by a number of rows:
This feature allows users to split their CSV files into smaller files based on the number of rows.
For example, if a user has a CSV file with 10,000 rows and they want to split it into 5 smaller files, they can use this feature to split the file into 5 files with 2,000 rows each.
Split by file size:
This feature allows users to split their CSV files into smaller files based on the file size.
For example, if a user has a CSV file that is 10 MB in size and wants to split it into 5 smaller files, they can use this feature to split the file into 5 files that are approximately 2 MB each.
Preset splitting options:
The tool offers several preset splitting options that allow users to quickly split their CSV files into smaller files based on common sizes, such as 1 MB, 2 MB, 5 MB, and 10 MB.
Method 3. Using SplitCSV
SplitCSV is a web-based software tool allowing users to split their large CSV files into smaller, more manageable ones.
To use SplitCSV, users need to visit the website and upload their CSV file.
The tool will then guide them through the splitting process, allowing them to choose the splitting options that work best for their needs.
The splitting options are;
Split by the number of rows
Users can choose the number of rows they want for each smaller file and the prefix and suffixes for the file names.
Split by file size
Users can choose the maximum file size they want for each smaller file and the prefix and suffixes for the file names.
Preset splitting options
Several preset splitting options that allow users to quickly split their CSV files into smaller files based on common sizes, such as 1 MB, 2 MB, 5 MB, and 10 MB.