•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 402,047 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,504 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 415 | Replies: 4 | Solved
![]() |
•
•
Join Date: Apr 2008
Posts: 39
Reputation:
Rep Power: 1
Solved Threads: 8
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:
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
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:
$ for file in `tar tvf /u8/sp_archive/2005.tar | grep 1274 | awk '{print $9}' | sed "s/\.\///" | head -5`
> do
> echo $file
> tar tvf /u8/sp_archive/2005.tar $file
> doneMy 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 4:55 pm.
•
•
Join Date: Oct 2007
Posts: 267
Reputation:
Rep Power: 1
Solved Threads: 26
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:
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
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!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
You can also do
but you're right, the quotes are probably easier.
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
----------------------------------------------
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
•
•
Join Date: Apr 2008
Posts: 39
Reputation:
Rep Power: 1
Solved Threads: 8
Niether of those solutions worked for me exactly as specified, however the following command worked fine:
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!
$ for file in `tar tvf /u8/sp_archive/2005.tar | grep 1274 | awk '{print $9}'`
> do
> tar xvf /u8/sp_archive/2005.tar "$file"
> doneThank you for the help - looks like I was just forgetting my quotes!
•
•
Join Date: Oct 2007
Posts: 267
Reputation:
Rep Power: 1
Solved Threads: 26
Nice creative fix. Good show!
, Mike
, Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
![]() |
•
•
•
•
•
•
•
•
DaniWeb Shell Scripting Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- A Few Small Issues (Linux Users Lounge)
- Open In New Window Php (PHP)
- Clearing Screen in the console (C++)
- Simple script loop question (Shell Scripting)
- Hard drive issues (*nix Hardware Configuration)
- SuSE 9.1 - Minor issues (*nix Software)
Other Threads in the Shell Scripting Forum
- Previous Thread: Trying to rewrite srm (safely remove): problem with spaces in filenames
- Next Thread: .bat need help with this simple command



Linear Mode