SUMMARY:Extracting files with a specific pattern from a tarred tape!

From: Vinay Somashekar (
Date: Tue Jan 04 1994 - 13:18:12 CST

Hi everybody,

here's a summary of the responses I've got so far. I hav'nt checked them out yet
but many thanx to all who responded!


<Q>: Hi netters,
<Q>: here's my question:
<Q>: -------------------
<Q>: how does one extract specific files from a tape which is stored in 'tar' format.
<Q>: OS: Sun OS 4.1.3
<Q>: Here's the situation:
<Q>: ---------------------
<Q>: A user has his whole homedirectory totalling about 600Mbytes, tarred onto a 8mm
<Q>: tape.
<Q>: user_homedir% tar cvf . /dev/rst10
<Q>: user_homedir%
<Q>: Now he has new a/c at another location where he is allocated limited space of
<Q>: only 20Mbytes on the hard disk.
<Q>: Since I cannot extract all the tarred files from the tape onto his new a/c,
<Q>: due to space constraints, the user requested that I get a specific type of
<Q>: files only from the homedirectory(excluding subdirectories).
<Q>: Example: Suppose the tape contents are as follows,
<Q>: user_new_a/c% tar tvf /dev/rst2
<Q>: ---- blah blah .....blah ./hello1.dat
<Q>: ---- blah blah .....blah ./hello1.f
<Q>: ---- blah blah .....blah ./hellof.dat
<Q>: ---- blah blah .....blah ./hello2.dat
<Q>: ---- blah blah .....blah ./subdir/subhello1.f
<Q>: ---- blah blah .....blah ./dir/subdir/ssubhello1.f
<Q>: ---- blah blah .....blah ./dir/subdir/ssubhello2.f
<Q>: ---- blah blah .....blah ./hello2.f
<Q>: ---- blah blah .....blah ./test1.f
<Q>: ---- blah blah .....blah ./test2.f
<Q>: .
<Q>: .
<Q>: .
<Q>: .
<Q>: and so on...
<Q>: The user requires all files with .f (dot f) extension at the
<Q>: main directory level only. i.e these files are
<Q>: hello1.f hello2.f test1.f test2.f
<Q>: from the above example only 4 files are to be extracted.
<Q>: Here is what I tried (but with no success):
<Q>: ------------------------------------------
<Q>: user_new_a/c% tar xvf /dev/rst2 `tar tf /dev/rst2 | grep '\.*.\.f'`
<Q>: the tape drive goes into motion but I get no output.
<Q>: Can someone tell me how I can go about solving this problem?
<Q>: Thanx
<Q>: cheers,
<Q>: -vinay
<Q>: #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
<Q>: # Vinay Somashekar Room Tel. # e-mail #
<Q>: # Computer Science NAC 8/216 (212)650-6181
<Q>: # Science Computing J 302 (212)650-7885 or 7886 #
<Q>: # CCNY/CUNY N.Y. N.Y. 10031 #
<Q>: #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#


[1] From helen! Sat Jan 1 14:38:52 1994

I believe that Gnu tar does what you want. You can find a copy on /packages/gnu/tar-* .

Robert L. McMillin | | Netcom:
13442 Wilson St. | Garden Grove, CA | 92644
            voice: 714-638-2459 | fax: 714-638-2384
            I'm only a guest at; THEY certainly wouldn't have these opinions!

[2] From Sun Jan 2 00:07:14 1994

I'm not sure whether you mistyped in your message, but if you intended to put:

user_new_a/c% tar xvf /dev/rst2 `tar tf /dev/rst2 | grep '\.*.\.f'`

then the problem is in the nested tar ^^^^^ command. Use the tvf options.

Also, it occurs to me that the filespec "'\.*.\.f'" doesn't need all the
dashes since it's in single quotes.


[3] From Sun Jan 2 08:20:27 1994

Try GNU tar - then you can put the list in a file and tell gtar to
get only those files. Example gtar -xvT <file> -f /dev/rst2

Or list the tape to a file tar tvf /dev/rst2 > /tmp/file 2>&1
Then grep out the .f files - to a file, then use
tar xvf /dev/rst2 `cat <file>`

user_new_a/c% tar tvf /dev/rst2

Ron Bolin					BellSouth Telecommunications
Georgia State Univ	
BellSouth Tele
Voice						404-529-3945

********************************************************************************************* [4] From Sun Jan 2 12:18:54 1994

To extract specific files from a tape like this you have to use it's name as it actually appears -- i.e. './test2.f' -- so to extract specific files would look something like:

tar xvf /dev/rst2 ./hello1.dat ./subdir/subhello1.f ./dir/subdir/ssubhello1.f

if you just want a particular directory and all it's files you can shorten this up to:

tar xvf /dev/rst2 ./dir/subdir

Hoep this helps...

-- * Bob Smith + mx: * * 838 Harmon Rd. + uucp: ur-valhalla!snuffy!bob * * Penfield, NY 14526 + office|voice mail: +1 716 724-6186 *

********************************************************************************************* [5] From eplunix! Sun Jan 2 14:14:23 1994

Gack: either do a "tar xvwf /dev/rst2" and interactively select the files to extract, or do a "tar tf /dev/rst2 >tar.list; tar xvf /dev/rst2 `grep \.f tar.list`" to get a list of what's on the tape and extract on that basis.

Your tar jobs are probably interacting badly

********************************************************************************************* [6] From Mon Jan 3 10:48:57 1994

try running the tar tf into a file and then running the tar x `cat file` I think the tar `tar` is causing problems. also this way you can examine the tar t output to see if it makes sense.

-- -Tony Rudie' <>

********************************************************************************************* [7] From era@TYRELL.NET Mon Jan 3 22:05:34 1994

Catch the list of files into a temp file. 'tar' does not deal well with multiple executions on one line.

I would use a different regular expression than you chose in your attempt:

tar tf /dev/rst2 >tempfile tar xvf /dev/rst2 `egrep '^\./[^/]*\.f$' tempfile`

That RE means:

^ start of line \. a literal DOT / a literal SLASH [^/]* as many non-slashes as you find ( this limits you to the top dir) \. a literal DOT f$ an 'f' at the end of line

Ed Allen

********************************************************************************************* [8] From Mon Jan 3 23:38:43 1994

Have you tried "%tar xvf /dev/rst?? *.f" ?

let me know if it works.

Rich ********************************************************************************************* [9] From Tue Jan 4 09:16:15 1994

The first tar in your command probably wants to start executing while the tape in the drive is rewinding after the second tar (which get executed first).

Why not split the command into something like tar tf /dev/rst2 | grep '\.*.\.f' >tmpfile tar xvf /dev/rst2 `cat tmpfile` (or tar xvf /dev/rst2 -I tmpfile)

All the best, Andre++ -- ------------------------------------------------------------------------------- Mechatronics Research Centre Twente -- Mobile Autonomous Robot Twente -- -- +31 53 893296 Twente University WB/WA P.O. box 217 NL-7500 AE ENSCHEDE THE NETHERLANDS

********************************************************************************************* [10] From Tue Jan 4 09:34:28 1994

One way is:

tar tf tarfile | grep PATTERN > /tmp/want tar xvf tarfile `cat /tmp/want`

Rememeber that grep patterns are different from shell filename patterns.

********************************************************************************************* [11] From: (Ido Dubrawsky)

Well, I can think of a couple of things you might want to try. The first is the following:

tar -xvf /dev/rst8 -I include_files

where include_files contains the names of the file which you wish to extract. I normally use this to tar up my /home directory, /usr/gnu, and /usr/local on my machine.

Another possibility which you may want to try, is:

tar -xwvf /dev/rst8

The w will cause tar to wait for your confirmation on each and every file. If you answer with anything other than a 'y', tar will go on to the next file. This method is _not_ recommended in your case as being good because the tar archive is 600MB big and you'd probably spend several days just getting the files that you want.

I hope this helps,

Ido Dubrawsky


#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# # Vinay Somashekar Room Tel. # e-mail # # Computer Science NAC 8/216 (212)650-6181 # Science Computing J 302 (212)650-7885 or 7886 # # CCNY/CUNY N.Y. N.Y. 10031 # #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#

This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:08:53 CDT