split
Linux Commands - Managing Files and Text

split

If you needed to split a file into smaller sections to manipulate in a program you could use the split command.


Options

-n line number the default number of lines is 1000


In this example the file data is split into sections having 5 lines each. Also notice that each new file has a prefix “datasplit_” added to the command to enable you to differentiate the new files.


split -5 data datasplit_


datasplit_aa

datasplit_ab

datasplit_ac

datasplit_ad

datasplit_ae

datasplit_af

datasplit_ag

datasplit_ah

datasplit_ai

datasplit_aj

datasplit_ak

datasplit_al

datasplit_am

datasplit_an

datasplit_ao

datasplit_ap

datasplit_aq

datasplit_ar

---cut---



In the example you can see that the default is to start with a file name of aa and precede onward. Here is a look at the content of datasplit_aa


cat datasplit_aa


acpi

adduser.conf

adjtime

aliases

aliases.db


Just as expected each file contains five lines of text.