Earendil
Earendil

Reputation: 25

Handle single files while extracting tar.gz

I am having a huge .tgz file which is further structured inside like this:

./RandomFoldername1/file1
./RandomFoldername1/file2
./RandomFoldername2/file1
./RandomFoldername2/file2
etc

What I want to do is having each individual file extracted to standard output so that I can pipe it afterwards to another command. While doing this, I also need to get the RandomFoldername name and file name so that I can deal with them properly from within the second command.

Till now the options I have are

  1. to either extract all of the tarball and deal with the structured files that I will be having, which is not an option since the extracted tar doesn't fit into the hard drive
  2. Make a loop that pattern match each file and extract one file at time. This option although that solves the problem, is too slow because the tarball is sweeped each time for only one file.

While searching on how to solve this, I've started to fear that there is no better alternative to this.

Upvotes: 0

Views: 69

Answers (1)

Etan Reisner
Etan Reisner

Reputation: 80931

Using tar the tool I don't believe you have any other options.

Using a tar library for some language of your choice should allow you to do what you want though as it should let you iterate over the entries in the tarball one-by-one and allow you to extract/pipe/etc. each file one-by-one as necessary.

Upvotes: 2

Related Questions