5

I split a gz file using gunzip piped to split:

time gunzip -c file.gz | split -l 500 -d -a 4 - pref_

Which generates the following files:

pref_0000 
pref_0001

I'd like to pipe those files to zip them again. I tried the following:

gunzip -c file.gz | split -l 500 -d -a 4 - pref_ | echo "file produced:" -
# Nothing

gunzip -c file.gz | split -l 500 -d -a 4 - pref_ | echo -
gunzip -c file.gz | split -l 500 -d -a 4 - pref_ | echo

Those do not work, how can I get an output from the split command? I expect to get the produced file names.

kaligne
  • 866

1 Answers1

3

You could use the --filter option of split to invoke zip on each split file

gunzip -c file.gz | split -l 500 -d -a 4 - pref_ --filter='zip $FILE'
iruvar
  • 16,725
  • 1
    I am sorry but my split does not have any option named filter. When I try it it says: split: unrecognized option '--filter=gzip $FILE' . Is it amatter of version? When I run split --help I cannot see any filtering option. – kaligne May 19 '16 at 10:42
  • @user3298319, ah you're probably missing gnu split – iruvar May 19 '16 at 12:06
  • 1
    it's strange because I have already installed gnu coreutils on my mac: brew install coreutils. – kaligne May 19 '16 at 13:00
  • @user3298319, i have access to two versions of GNU split. V 8.24 supports --filter, V 5.97 does not. So I'm guessing it's about the version – iruvar May 19 '16 at 15:07
  • @iruvar How can I find my version of split? I have the same problem, and installed split with the same command. But my error is, split: illegal option -- - :D – Alex Jun 29 '17 at 20:07
  • @alex, are you on a Mac? – iruvar Jun 29 '17 at 20:51
  • @iruvar Yes, I am. – Alex Jun 29 '17 at 20:55
  • @alex, could be one of two things, you're missing GNU split in which case brew install coreutils should do the trick as long as you make sure GNU split takes path precedence over the default split. Alternately you could have an older version of GNU split – iruvar Jun 29 '17 at 21:30