In this article, we will be discussing the useful cases of split unix command with examples.
split unix command
it split a file into pieces.
SYNTAX for the Split command
split [-linecount | -l linecount | -b bytes] [file [name] ]
This command is widely used to split the files into smaller small for variour purpose 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.
Other example would be split the big files and then transmit over network so that we dont get disconnection issues
How to split the files based on lines
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.
awk command : Complete guide on awk command in Unix with lot of examples
sed command : A good overview of sed command and difference between awk and sed and much more
grep command : A lot of grep command with options
windows grep equivalent: Grep equivalent in window OS
how to tar a directory in Linux