I've a 100GB file and I want to split into 100 of 1GB file each (by line break)
e.g.
split --bytes=1024M /path/to/input /path/to/output
For the 100 files generated, I want to apply gzip/zip to each of these files.
Is it possible to use a single command?
Use "--filter":
split --bytes=1024M --filter='gzip > $FILE.gz' /path/to/input /path/to/output
A one-liner using a conditional is as close as you can come.
gzip
will only run ifsplit
is successful because of the conditional&&
which is also between thecd
andsplit
making sure thecd
is successful, too.. Note thatsplit
andgzip
output to the current directory instead of having the ability to specify the output directory. You can make the directory, if needed:To put it all back together:
Using this command with
-d
option allows you to generate numeric sufixes.Files generated:
A bash function to compress on the fly with pigz