Splitting files by line count on the command line

March 30, 2011

Two new command line tools I learnt of today. To count the number of words or lines in a text file there is the wc utility.

wc -l myfile.csv

Returns the number of lines in the specified text file. If you want to then split that into several smaller files you can use the split utility. By default this splits files by number of bytes, but with the -l option you can split by number of lines

split -l 100 myfile.csv

The new files appear in the current working directory named aa, ab, ac, ed etc


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: