As an example, we have a file named primary_data_file.txt that contains 616 lines of data. We want to split this into 4 files, with the equal amount of lines in each.
1 2 |
$ wc -l primary_data_file.txt 616 primary_data_file.txt |
The following command should do the trick:
1 |
split -da 1 -l $((`wc -l < primary_data_file.txt`/4)) primary_data_file.txt split_file --additional-suffix=".txt" |
The option -da generates the suffixes of length 1, as well as using numeric suffixes instead of alphabetical.
The results after running the command are the following files:
1 2 3 4 5 6 |
$ wc -l split_file* 154 split_file0.txt 154 split_file1.txt 154 split_file2.txt 154 split_file3.txt 616 total |