How can I split and write the output of my command in Linux bash, to multiple (text) 5M files (number of files does not matter)?
How to split and write the output of a linux command to multiple files of a specific size?
3.3k views Asked by UserYmY At
2
There are 2 answers
0
On
Another answer that adds the --filter
option to support the request from this comment:
my-command | split -b 500m -d --filter='cat > $FILE; zip -m $FILE.zip $FILE' - myFile.
This tells split
to use the command provided in parameter --filter
to produce the files.
The command dumps the data it receives at stdin
into the file $FILE
(the variable is set by split
with the name of the file it computed) then asks zip
to move the file into the archive $FILE.zip
.
Pipe its output to
split
.Example:
will produce files of 5GB having the names
myFile.aaa
,myFile.aab
,myFile.aac
a.s.o.Use
-l
instead of-b
to produce files with the specified number of lines instead of bytes. Readman split
or the online documentation.