-3

So I have a directory of thousands of tar balls in Unix. I want to iterate over all those tar balls and extract a specific file (uniquely appended with .vcf.gz), out of each tar ball and move it to a different directory?

I can't figure out how to do this effectively. Please help.

  • 1
    Please be more precise about how you have the names of the files stored and how you deduce the names of the output directories. Thank you. – Mark Setchell Feb 02 '21 at 11:50
  • the file i want *.vcf.gz exists within the tar ball. The tar is named *_output.tar.gz, within that there is a directory called ./results in which, *.vcf.gz exists. * = unique alphanumeric idenitifier. This identifier is consistent between the tar ball and the .vcf.gz file. Output directory can be anything. Lets call it ./output_vcfs – cocathilla Feb 02 '21 at 12:04
  • I don't understand your description, but suspect **GNU Parallel** can do it. Example here... https://stackoverflow.com/a/50924295/2836621 – Mark Setchell Feb 02 '21 at 12:10

1 Answers1

0

Loop through the tar files in the directory and then perform the tar command on each file.

for i in *tar.gz;
do 
   tar -xvf "$i" -C "/path/to/new/folder" "*.vcf.gz";    # Use -C to switch directory before extract and put extension to search for in tar file in quotes.
done
Raman Sailopal
  • 12,320
  • 2
  • 11
  • 18