#!/usr/bin/perl $bob = 10; # Number of files to extract at a time. $USAGE = " USAGE: etar -options args SYNOPSIS: extended tar OPTIONS: -x eXtract files. -l list files. -p:pattern Pattern to match filenames. -i:infile File can be .tar, .tgz, .tar.gz -o:outfile File can be .tar, .tgz, .tar.gz -v Verbose EXAMPLES: o etar -l -i:pdtl.tgz -p:*.tex List all tex files in pdtl.tgz o etar -x -i:pdtl.tgz -p:*.tex Extract the same. NOTES: Extracts $bob files at a time to avoid huge input to system. AUTHOR: GPL(C) Mohsin Ahmed http://www.cs.albany.edu/~mosh "; $filepat = '.'; while( $_ = $ARGV[0], /^-/ ){ shift; m/^--$/ && last; m/^-v/ && $verbose++; if( m/^-i:(.+)/ ){ $infile = $1; } if( m/^-\?/ ){ print $USAGE; exit; } m/^-o:(.+)/ && ($outfile = $1); m/^-p:(.+)/ && ($filepat = $1); m/^-l$/ && $listing++; m/^-x$/ && $extracting++; } die $USAGE unless $infile; die "Cannot read '$infile'.\n" unless -r $infile && -f $infile; # zl gunzip -c $1.tgz | tar -tvf - # zlg gunzip -c $1.tgz | tar -tvf - | grep $2 # zx gunzip -c $1.tgz | tar -kxvf - $2 # zxv gunzip -c $1.tgz | tar -Oxvf - $2 | more # zs tar -cvf - $2 $3 $4 $5 $6 | gzip > $1.tgz # zss tar -cvf - $1 | gzip > $1.tgz if( $infile =~ m/z$/ ){ $lscmd = "gunzip -c $infile | tar -tvf - |"; $excmd = "gunzip -c $infile | tar -kxvf - "; }else{ $lscmd = "cat $infile | tar -tvf - |"; $excmd = "cat $infile | tar -kxvf - "; } print STDERR "lscmd = $lscmd \n"; open( LS, $lscmd ) || die "Failed: $lscmd\n"; while( $lsline = ){ chop $lsline; # should it be chomp? print STDERR "$lsline\n" if $verbose; # -rw-r--r-- 801/801 3871 Mar 29 02:50 1993 tab2.pic ( $perm, $id, $size,$month,$day,$time,$year,$name) = split( ' ', $lsline ); next unless $name =~ m/${filepat}/; print STDOUT "$lsline\n" if $listing; push( @files, $name ); } if( $extracting ){ # Only $bob files at a time to avoid system( huge line ). while( @somefiles = splice( @files, 0, $bob ) ){ print STDERR "Extracting: $excmd @somefiles\n" if $verbose; system("$excmd @somefiles"); } } # EOF