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
> done

My output:

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

9 Years
Discussion Span
Last Post by eggi

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*"

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,


Votes + Comments
forgetting quotes seems to have been my issue!

Niether of those solutions worked for me exactly as specified, however the following command worked fine:

$ for file in `tar tvf /u8/sp_archive/2005.tar | grep 1274 | awk '{print $9}'`
> do
> tar xvf /u8/sp_archive/2005.tar "$file"
> 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!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.