Home » Unix command and scripts » split command in Unix

split command in Unix

In this article, we will be discussing the use cases of the split  Unix command with examples.

split Unix command

(1) it split a file into pieces.
(2) SYNTAX for the Split command

split [-linecount | -l linecount | -b bytes]  [file [name] ]
-l line number
-b bytes

(3) This command is widely used to split the files into smaller small ones for various purposes like parallel processing.  You have 1000 lines command where each command can be executed parallelly, then you can split the files in example 4 files and execute them parallely to finish the processing in time.

(4) Another example would be to split the big files and then transmit over the network so that we dont get disconnection issues

How to split the files based on lines

Here is the example

split -l 100 x.txt  z

This  would split the file “x.txt” into files beginning with the name “z” each containing 100 lines of text each

$split -l 100 x.txt z 
$ls 
zaa zab zac z.txt 

This will output three files, zaa, zab, and zac, and each one will be 1,00 lines long.

How to split the files based on bytes

We can use the split option -b to enable the splitting based on bytes

split -b 40k f1.txt segment 

This will output four 40KB files: segmentaa, segmentab, segmentac, and segmentad.

Also Read
awk command: Complete guide on awk command in Unix with a lot of examples
sed command: A good overview of sed command and the difference between awk and sed and much more
grep command: A lot of grep commands with options
find command in Unix with example: find command in Unix with an example, How to use find command in Unix. Unix find directory command, how to find find based on modified time
windows grep equivalent: Grep equivalent in window OS
how to tar a directory in Linux

See also  Sed command

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top