The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to write bash script to explode multiple zip files siegfried Shell Programming and Scripting 3 02-07-2009 09:54 PM
Executing Multiple .SQL Files from Single Shell Script file anushilrai Shell Programming and Scripting 3 04-07-2008 11:09 AM
How to execute multiple(batch) oracle script in unix mechine ravi gongati Shell Programming and Scripting 2 03-21-2008 07:37 AM
Converting Shell script to Dos batch files darwinkna Shell Programming and Scripting 1 05-12-2006 12:01 PM
Schedule a Batch file to delete files at particular intervals Indom Windows & DOS: Issues & Discussions 6 02-04-2004 12:57 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-13-2007
kuliksco kuliksco is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 10
Question 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.

Last edited by kuliksco; 11-13-2007 at 01:11 AM..
  #2 (permalink)  
Old 11-13-2007
gus2000 gus2000 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 157
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" ?
  #3 (permalink)  
Old 11-13-2007
kuliksco kuliksco is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 10
Quote:
Originally Posted by gus2000 View Post
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
  #4 (permalink)  
Old 11-13-2007
gus2000 gus2000 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 157
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).
  #5 (permalink)  
Old 11-13-2007
kuliksco kuliksco is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 10
Quote:
Originally Posted by gus2000 View Post
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.

Last edited by kuliksco; 11-13-2007 at 11:37 AM..
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:36 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0