It seems to me that one might describe what you want as a “stream editor” for tar files that allows you to apply the
--strip-components pathname translation. The idea is to take a tar file as input and write a modified tar file as output.
None of the tars who's documentation I checked (GNU tar, star, bsdtar) seem to support your exact operation.
bsdtar is interesting though. Its
@archive syntax seems like it would come close to letting you read a tarfile and write a modified one, but the manpage entry for
--strip-components says that it only works in
t modes). If it did work in
c mode, you could use something like this:
wget -O - <url> | bsdtar -c --strip-components 1 -zf new.tar.gz @-
I do not have bsdtar on my machine (it is tar in FreeBSD, as well as tar in Mac OS X 10.6 (older releases use GNU tar); it is available as bsdtar on some Linux distributions: Debian GNU/Linux, Ubuntu, and some RPM-based distributions), but looking at the code, I am sure that invocation will just cause an “Option --strip-components is not permitted in mode -c” error.
If you want this, you will probably have to roll your own program (or get someone to do it for you). Fortunately, this may not be as hard as it sounds. bsdtar is based on the very nice libarchive library. It looks like it would be fairly straightforward to make a program that does what you want. Since bsdtar already has most of the code you would need to copy one archive to another (through its
@archive handling), you could probably even do it by adding some functionality to bsdtar. An simple “damn the architecture, just get it done” approach might be to enable
c mode and add a call to
append_archive. The problem with this approach is that all the
edit_pathname transformations would be applied to both entries from
@archives and the pathnames of actual files specified through other means (command line args,
-T pathname lists, etc.). This behavior may or may not in the best interest of official bsdtar (there is probably some reason
--strip-components is not already enabled for