

4 indicates to split the file into 4 equal parts or sections, and 1/4 indicates to write to stdout the 1st of the 4 sections. The option "-n 1/4" does not create any output files. split command to display only a section of the file: And hence, the file F0 contains the complete 4th line "Solaris", and the rest goes to the 2nd file.ġ0. The option "-n l/2" enables to split on the basis of complete lines. Split file into 2 files with complete lines of output: As shown above, since the file has 42 characters, it is divided into 21 characters each.ĩ. Note: -n divides the file into equal lengths on the basis of the byte count of the files. By specifying the "-n 2", the file is split equally into 2 files as shown below: Split a file into 2 files of equal length:Īt times, the requirement can be to split a file equally into 2 files, unlike earlier case where the split is based on number of lines per output file. Note: The commands below use the option -n which is not available in all Unix flavors.Ĩ. Similarly, to split the file with 1MB of data per OUTPUT file: This will split the file with 1 KB of data per OUTPUT file.


Split file with Kilobytes or Megabytes of data per OUTPUT file: The new line character of the 2nd line moved to the 2nd output file.ħ. The file F0 contains 10 characters 5 characters of first line (Unix + new line) and 5 characters of second line (Linux). The byte count includes the new line character present at the end of the line as well. The -b option of split divides the file on the basis of byte count. Split file into multiple files with 10 bytes per OUTPUT file: With this, the files generated will be "F00", "F01", "F02", and so on.īy enabling the option -a to 1, single digit numeric suffix is set.Ħ.

The option -d of split enables a numeric suffix. Split file into multiple files with a numeric suffix: By providing the suffix length as 1, the files created are "Fa","Fb", and so on.ĥ. The option -a of split allows to control the length of suffix. For our example, a single character suffix would suffice. If the number of output files to be created is huge, this makes sense. In the above examples, the suffixes generated are "aa","ab" and so on. Split file into multiple files with a single character suffix: Since the suffix provided is "F", the files created are "Faa","Fab", and so on.Ĥ. The suffix, if provided, is the last argument of the split command. Split file into multiple files with a user defined prefix: The file "xab" contains the 4th till 6th line, and the file "xac" contains the last line.ģ. Since the input file contains 7 lines, the output files contain 3, 3 and 1 respectively. The option -l specifies the number of lines per output file. Split file into multiple files with 3 lines each: Since the input file does not contain 1000 lines, all the contents are put into only one output file "xaa". By default, the output files generated contains the prefix "x", and the suffix as "aa", "ab", "ac" and so on.Ģ. The output file generated in this case is: The split command splits the file into multiple files with 1000 lines into each output file by default. Let us consider a file with the following content: In this, we will discuss it using the split command itself:
#COMMAND TO CREATE A ZERO BYTE FILE IN UNIX HOW TO#
In an earlier article, we discussed how to split files into multiple files using awk. The splitting can be done on various criteria: on the basis of number of lines, or the number of output files or the byte count, etc. Split command in Unix is used to split a large file into smaller files.
