split - Invaluable Tool for Dealing with .csv Files

I just learned about split. It’s a linux command line utility that splits a text file in to however separate files, each however many lines you specify.

Here’s a usage example. I have a mailing list of about 20,000 names and addresses. It’s stored as a .csv file, so it’s basically just a big text file. Each name/address is on a separate line. Because the responses will be overwhelming if we send something out to all 20,000 people at once, we want to stretch the mailings out over a period of time - say 600 names/addresses per day.

Unfortunately, your mailing house needs separate files for each of the mailings - they somehow can’t split the file into parts of 600 names each. So, instead of spending half an hour copying and pasting rows in Excel or OpenOffice, just use split.

The basic syntax is

split -l 600 yourfile.csv 

, where 600 is the number of lines you want per file, and yourfile.csv is, of course, the file you want to have split. With a list of almost 21,000 names, the result for me was the original file, plus 35 text files with 600 names in them. The files that split creates are, by default, named xaa, xab, xac, etc. For me, my files went all the way through xbi.

split is part of GNU coreutils, so nearly all linux distributions should have a copy of it. I hope this helps someone - I know it saved me a lot of work. grin


Posted on Apr 23, 2009 - 10:32 AM

Leave A Comment!!

Please enter the letters or word you see in the image below:

Name:

Email:

Location:

URL:

Remember this information for next time

E-mail me about follow-up comments