Extracting from archive | compressing to new archive

Hi there,

I have one huge archive (it's a system image).
I need sometime to create smaller archives with only one or two file from my big archive.
So I'm looking for a command that extracts files from an archive and pipe them to another one.
I tried the following :

tar -xzOf oldarchive.tgz ./file1 ./file2 | tar -czf newarchive.tgz

But it doesn't seem to work: it says:

tar: Cowardly refusing to create an empty archive

Can anybody explain me why?
Does anybody have a better idea?

Thanks for your help.
Santiago

i couldnt understand why you used '0' in the code in '-xz0f'. I think it would work even if u dont use it in the first place. Try that out.

Hey bdiwakarteja,
And thx for your interest.
-O means output to stdout instead of a file.
I thought it was necessary to redirect to another archive.
I can't try without it right now but I will do it asap.
Thx for your help
Santiago

The problem is that tar can't archive files from stdin, only when they're given as arguments on the command line. I'm afraid you won't get around extracting the 2 files, and then tar'ing them again.

Thanks pludi for your help.
This is a bit anoying because I'm not the administrator of the machine.
But the big archive contains files owned by root that are meant to be used for computers that I administrate.
So if I extract them to the filesystem before tar'ing them again, they will be owned by me and not root anymore.
Does anybody thinks of a way to get around the problem?
Thanks for your help

Well, with -O you'd have lost the permissions anyways, as those can only be bound to a file, not to a stream. So IMO your best chance would be to extract the 2 files, move them to a machine you administer, and then create a new archive from them after you've corrected the permissions.