bash - batch script for extracting one file from multiple tar files

so i have hundreds of files named history.20071112.tar
(history.YYYYMMDD.tar)

and im looking to extract one file out of each archive called status_YYYYMMDDHH:MM.lis

here is what i have so far:

for FILE in `cat dirlist`
do
tar xvf $FILE ./status_*
done

dirlist is a text containg the full path to the tar files i want to extract the single file from:
/export/home/psxfer/history/archive/history.20070101.tar
/export/home/psxfer/history/archive/history.20070102.tar
/export/home/psxfer/history/archive/history.20070103.tar
/export/home/psxfer/history/archive/history.20070104.tar
/export/home/psxfer/history/archive/history.20070105.tar
etc...

the problem is that it doesnt look like tar is liking the wildcard and needs the exact file name of the single file to extract so it's not working.

anyone have any ideas? or would i need to run tar -tf history.YYYYMMDD.tar for each file to get the exact filename for the .lis file?

thanks in advance!!

i forgot to mention that this is solaris 8 if that makes a difference.

Well, this *should* work. There are caveats, tho. First, the pattern should be quoted, since it will be expanded by the shell if it matches any files in the current directory. Second, the filename must match precisely, path and all. Are you sure the file is stored in the archive as "./foo.bar" ?

hmm...i tried with the quotes but the ./status_* still isnt finding a match. here is the contents of one of the tar files:

tar -tf /export/home/psxfer/history/archive/history.20070101.tar
./status2_2007010107:00.lis.gz
./status3_2007010107:00.lis.gz
./status_2007010107:00.lis.gz
./RSCAR084_482134.pdf.gz
./rscem001_482111.lis.gz
./rscem002_482114.lis.gz
./rscem006_482110.lis.gz
./rscem006_482113.lis.gz
./rscbi068_482140.lis.gz
./RSCPT002_482144.pdf.gz
./rscpt003_482143.txt.gz
./rscpt004_476773.txt.gz

Curious, I didn't have a problem extracting from tar via wildcards on OSX (it was the nearest Unix machine). I guess you'll need to extract the name first, as you already suggested, although it means scanning each archive twice (arrrrrg).

ok got it working. i ended up using:

for FILE in `cat $1`
do
LIS=`tar -tf $FILE | grep ./status_`
tar -xvf $FILE $LIS
done

easier than i thought. not sure if there was a better way other than using grep.

thanks again for the help.