Kris Kris - 6 months ago 15
Linux Question

How to split one text file into multiple *.txt files?

I got a text file

file.txt
(12 MBs) containing:

something1
something2
something3
something4
(...)


Is there any way to split
file.txt
in to 12 *.txt files let say
file2.txt
,
file3.txt
,
file4.txt
(...) ?

Answer

you can use the linux bash core utility split

split -b=1M -d  file.txt file 

Note that M or MB both are OK but size is different. MB is 1000 * 1000, M is 1024^2

If you want to separate by lines you can use -l parameter.

UPdae

a=(`wc -l yourfile`) ; lines=`echo $a/12 | bc -l` ; split -l=$lines -d  file.txt file