Have you ever been tasked with splitting a gigantic spreadsheet or CSV into smaller segments? When using an application like Excel, this can be a huge pain in the butt.

Thankfully, using a simple command from the terminal, you can split these huge files into segments in literal seconds! Let’s get started!

Let’s pretend you have a CSV file that contains 60k rows, each consisting of 8 columns. Sure, you could open the file, select a couple of thousand rows at a time, copy into a new spreadsheet and save that new file. Although this will do the trick, Linux (or any Unix based OS) offers an even better solution.

In order to split a large file into smaller files, use the split command:

split [options] yourfile segmentnames 
You can split a file by line number: -l linenumber, or bytes: -b bytes. In my case, I’m typically working with spreadsheets:

split -l 2000 myfile segment

The command above will split the existing file into segments of 2000. If the original file consists of 60k lines, the resulting output will create 30 files consisting of 2000 lines.

 

Bonus!

Once you’ve split your files, you’ll find that each file contains no extension. You can quickly and easily rename each file, adding the appropriate extension type. In my example, I’ll use .csv. Once your segments have been created, select all of the newly created files > right click > rename (or F2). Hit Enter or click the “Rename” button and PRESTO! All of your new segments have been renamed with the appropriate file extension:

 

This is a relatively simple example of a rename template. Much more can be accomplished if you need a more specific naming schema. I recommend playing around with additional options by clicking “+Add” on the right side of the input field.

I use the split command at least once a week. It has saved countless hours of screwing around, manually splitting files up. The beauty here: Even if your file doesn’t open due to its size, the entire process of splitting can be done without cracking the file open.

Divi WordPress Theme