Linux - Example to split a file in to small file, Create split input file
Example to split a file in to small file
Create split input file# for i in {1..1000}; do echo "$i" >> split_input; doneFirst we shall create an input file for splitting a file. With the above command we shall create a large input file for splitting a file which has 1000 lines. File split_input file will be having 1000 lines which we shall use it for spliting in to small chunks, 100 lines per file.
How to split a file
# split -l 100 split_input split_output
Output:
# ls -l -rw-r--r--. 1 id825385 linux 3893 Jun 18 16:28 split_input -rw-r--r--. 1 id825385 linux 292 Jun 18 16:32 split_outputaa -rw-r--r--. 1 id825385 linux 400 Jun 18 16:32 split_outputab -rw-r--r--. 1 id825385 linux 400 Jun 18 16:32 split_outputac -rw-r--r--. 1 id825385 linux 400 Jun 18 16:32 split_outputad -rw-r--r--. 1 id825385 linux 400 Jun 18 16:32 split_outputae -rw-r--r--. 1 id825385 linux 400 Jun 18 16:32 split_outputaf -rw-r--r--. 1 id825385 linux 400 Jun 18 16:32 split_outputag -rw-r--r--. 1 id825385 linux 400 Jun 18 16:32 split_outputah -rw-r--r--. 1 id825385 linux 400 Jun 18 16:32 split_outputai -rw-r--r--. 1 id825385 linux 401 Jun 18 16:32 split_outputajBy using the above command now the file has been splitted in to 100 lines per file. You can see the above output which has splitted small chunks of files.
The topic on Linux - Example to split a file in to small file is posted by - Guru
Hope you have enjoyed, Linux - Example to split a file in to small fileThanks for your time