I have a large file
foo.tar.xz that contains a lot (say 200000) of files. I figured out that this archive contains some (around 5000) files I don't want. I don't have sufficient disk space to decompress the whole thing onto my disk; additionally, I fear attributes / rights might get lost if I do so. I have enough space to host two copies of the compressed archive though. Is there a tool to remove some of the files from the archive (specified with a regex on the filename) on-the-fly, i.e. without unpacking the archive into individual files?
I have a large file
Use it like this, for example:
tar -vf yourArchive.tar --delete your/path/to/delete
Beware: It will most likely not work on any kind of magnetic tape medium. But
tar has no problems working in a pipe, so you can just use a temporary tar file and overwrite the tape with that afterwards. It also won't work on compressed files, so you would need to uncompress the file.
Also, the operation will be rather slow in any case, due to the (by design) packed linear nature of tar archives.
(edited, as I misunderstood the question, which was since edited also)
The best you can do is to extract, delete, and recompress the entire file.
unxz < foobar-old.tar.xz | tar --delete foo/bar | xz > foobar-new.tar.xz
It's not possible to delete files from a tar directly.
tar is a stream, originally intended for tape drives which do not do random seeks well - while in theory it could be possible on a disk filesystem to punch a hole / rewrite the remaining file, with compression the point is moot as most if not all compression methods heavily depend on contents that occured earlier in the file. In order to do this in place you would need very detailed knowledge about both the compression method as well as the tar file format. That's complexity to a point no one would even bother with it. It's cheaper to just keep the files around and ignore them.
If you need this functionality, tar is probably not what you want.
According to the manual, you can pass a list of filenames to
tar to only extract those. For example:
$ tar --file archive.tar --list foo bar baz $ tar --file archive.tar --extract foo