943,712 Members | Top Members by Rank

Ad:
Jul 17th, 2008
0

tar issues...

Expand Post »
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.
Similar Threads
Reputation Points: 13
Solved Threads: 9
Junior Poster in Training
omrsafetyo is offline Offline
58 posts
since Apr 2008
Jul 17th, 2008
1

Re: tar issues...

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:

Quote ...
# 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
Reputation Points: 102
Solved Threads: 47
Posting Whiz
eggi is offline Offline
399 posts
since Oct 2007
Jul 18th, 2008
0

Re: tar issues...

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.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Jul 22nd, 2008
0

Re: tar issues...

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!
Reputation Points: 13
Solved Threads: 9
Junior Poster in Training
omrsafetyo is offline Offline
58 posts
since Apr 2008
Jul 22nd, 2008
0

Re: tar issues...

Nice creative fix. Good show!

, Mike
Reputation Points: 102
Solved Threads: 47
Posting Whiz
eggi is offline Offline
399 posts
since Oct 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: Trying to rewrite srm (safely remove): problem with spaces in filenames
Next Thread in Shell Scripting Forum Timeline: .bat need help with this simple command





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC