-1

I have a '.tar' file that contains multiple '.tar.gz' files. Within each of these '.tar.gz' there is a '.faa' file that I need. I don't want to unpack everything else.

I have been searching through a lot of old questions here but I seem to be getting stuck on one part of my code. Based on what I've read I wrote this:

tar -zxOf /pathtofolder/folder1.tar ".tar.gz" | tar -zxvf - '.faa' 

However, it is only pulling from just one of the '.tar.gz' and not the other 6:

x 2758568008/2758568008.genes.faa

I then tried a for loop in case that was it:

tar -zxOf /Users/gchaput/Desktop/TestFolder/img_data_29800-13.tar | for file in '*.tar.gz'; do tar -zxf "$file" '*.faa'; done

But I get the error:

tar: Error opening archive: Failed to open '*.tar.gz' 

I have a macOS 10.14.1 and so wildcard is not an option for me unfortunately.

  • 1
    Remove the single quotes around *.tar.gz and retry with your loop. – Weijun Zhou Mar 20 at 12:58
  • @WeijunZhou Ah it worked! Thank you so much- I can't believe what a quick fix that was. Goes to show how helpful it is to have other eyes on what you're doing. – Gina Mar 20 at 13:00
  • To complement @WeijunZhou 's comment, the single quotes are preserving the * character to be expanded. Take a look at the following SE Link: stackoverflow.com/q/6697753/2231796 – user34720 Mar 20 at 13:13
  • I can't understand use of | for first tar command do extract file, piping look useless here. (not useless it add confusion). – Archemar Mar 20 at 13:23
0

Use " " in stand of ' ' which is always good for linux!

  • can you explain how changing the quoting would fix the problem at hand? – Jeff Schaller Mar 20 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.