tar issues...

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Apr 2008
Posts: 58
Reputation: omrsafetyo is an unknown quantity at this point 
Solved Threads: 9
omrsafetyo omrsafetyo is offline Offline
Junior Poster in Training

tar issues...

 
0
  #1
Jul 17th, 2008
Hey,

I'm trying to unpack certain files from a tar archive - I don't want to unpack all of the 1.2GB file, just a particular bunch of it.

I tried an obvious command:

tar xvf /u8/sp_archive/2005.tar *1274*
All files I want to extract have "1274" in the name; I want to extract every file that does.

This produced nothing. I started working with tvf to see if I can actually get the desired files base on my input. Here is what I came up with:
Shell Scripting Syntax (Toggle Plain Text)
  1. $ for file in `tar tvf /u8/sp_archive/2005.tar | grep 1274 | awk '{print $9}' | sed "s/\.\///" | head -5`
  2. > do
  3. > echo $file
  4. > tar tvf /u8/sp_archive/2005.tar $file
  5. > done

My output:
mu1274.Apr.gz
mu1274.Apr.log
mu1274.May.log
mu1274.Apr.sp_table.gz
mu1274.Apr.index.gz

That is, just the results of my echo command. The files are there and I know those are the filenames within the archive - but they don't seem to be getting unpacked (or processed as if they would be if I specified x instead of t. If I do, they don't get unpacked).

Any ideas?

AIX 4.3
Last edited by omrsafetyo; Jul 17th, 2008 at 5:55 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 399
Reputation: eggi will become famous soon enough eggi will become famous soon enough 
Solved Threads: 47
eggi eggi is offline Offline
Posting Whiz

Re: tar issues...

 
1
  #2
Jul 17th, 2008
Hey There,

I'm using FreeBSD 4.1 right now and got it to work by just wrapping the regular expression in quotes. It may be that your shell is interpreting the * character before it passes it to tar:

# tar xvf bin.tar "*perl*"
perly
perltest.pl
The example above is what I used to test quickly and it failed without the quotes.

Let me know if that doesn't work. We've got some AIX boxes I can specifically try this on tomorrow. Also, if this doesn't work, try the "-L" option and put your string in a file. A bit of a pain, unless you want to match 100 unique files and don't want to type them on the command line, but will probably work, also

Best wishes,

Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,467
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 267
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: tar issues...

 
0
  #3
Jul 18th, 2008
You can also do

Shell Scripting Syntax (Toggle Plain Text)
  1. tar xvf bin.tar \*perl\*

but you're right, the quotes are probably easier.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 58
Reputation: omrsafetyo is an unknown quantity at this point 
Solved Threads: 9
omrsafetyo omrsafetyo is offline Offline
Junior Poster in Training

Re: tar issues...

 
0
  #4
Jul 22nd, 2008
Niether of those solutions worked for me exactly as specified, however the following command worked fine:
Shell Scripting Syntax (Toggle Plain Text)
  1. $ for file in `tar tvf /u8/sp_archive/2005.tar | grep 1274 | awk '{print $9}'`
  2. > do
  3. > tar xvf /u8/sp_archive/2005.tar "$file"
  4. > done
It was about 40 files total - so it would have been a bit of a pain to do it all by hand, which is why I love for loops.

Thank you for the help - looks like I was just forgetting my quotes!
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 399
Reputation: eggi will become famous soon enough eggi will become famous soon enough 
Solved Threads: 47
eggi eggi is offline Offline
Posting Whiz

Re: tar issues...

 
0
  #5
Jul 22nd, 2008
Nice creative fix. Good show!

, Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Shell Scripting Forum


Views: 1085 | Replies: 4
Thread Tools Search this Thread



Tag cloud for Shell Scripting
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC