I've got a folder with thousands of gzipped archive files that contain several XML files. Now I need a script that loops over all archive files and selectively extracts a file with a certain filename (i.e. fileofinterest.xml) into a directory that has to be created by using the filename of the gzipped archive without the extension tar.gz.
So here's a sample of the archive directory containing the gzipped archive files and the desired output-directory with generated directories and extracted files:
home/
├─ archives/
│ ├─ archive.20.01.tar.gz
│ ├─ archive.20.02.tar.gz
├─ extracted/
│ ├─ archive.20.01/
│ │ ├─ fileofinterest.xml
│ ├─ archive.20.02/
│ │ ├─ fileofinterest.xml
This is my code so far, creation of directories is completely missing:
for f in ./*.tar.gz; do echo "Processing $f"; tar -x -f $f -C ../extracted/ fileofinterest.xml; done