On Wed, Nov 06, 2002 at 05:01:36AM -0800, Drew Poulin wrote:
> I'm trying to extract the files from 108 .tar archives located in a single
> directory. 
[...]

Cameron Simpson once posted the included script to one of the RH lists - it
deals with many different types of archives as well as with multiple
archives. I've been using it on all my machines ever since...

(I'll include it inline, as I'm not sure about attachments and list policy)

Cheerio,

Thomas

------------------ SNIP HERE ----------------------------------------------
#!/bin/sh
#
# xtract
# (c) by Cameron Simpson <[EMAIL PROTECTED]>
#
# Install in your path and make executable, then make a link called 'toc'
# to it (ln -s xtract toc)
#
# Usage:
# xtract ARCHIVE(S)
# Unpacks contents of one or more archives
#
# toc ARCHIVE(S)
# Shows contents of one or more archives
#
#
# TOC or extract various archive formats.
#       - Cameron Simpson <[EMAIL PROTECTED]>
#
# Iterative analysis of extensions; the combinations were getting too numerous.
#       - cameron 22jan99
#

cmd=`basename "$0"`

case "$cmd" in
    xtract)     mode=extract ;;
    x)          mode=extract ;;
    toc)        mode=toc ;;
    t)          mode=toc ;;
    *)  echo "$cmd: Who am I? Please call me either as \"toc\"/\"t\" or as 
\"xtract\"/\"x\"" >&2
        exit 1
        ;;
esac

pageit=
## [ -t 1 ] && pageit=1

toc_cpio='cpio -icvt'           extract_cpio='cpio -icvdm'
toc_tar='tar tvf -'             extract_tar='tar xvf -' # or use 'tar xvf -'
toc_uu="egrep '^(begin|end) '"  extract_uu='uudecode /dev/fd/0'
toc_lzh='xlharc v'              extract_lzh='xlharc x'
toc_zip='unzip -l $f'           extract_zip='unzip -d . $f'
#toc_rpm='rpm -q -p "$f" -i -R --provides -l'
        #                       extract_rpm='rpm -U -v -h "$f"'

xit=0

for f
do  echo "$f ..."
    (
      pipe="<\"\$f\""
      pipeext=
      format=

      # break name up into pieces
      case $f in */*)   b=`basename "$f"` ;;
                 *)     b=$f ;;
      esac
      oIFS=$IFS; IFS=.; set x $b; shift; IFS=$oIFS

      nth=$#
      while [ -z "$format" -a "$nth" -gt 0 ]
      do
          # get nth arg
          eval "ext=\$$nth"

          filt=
          case $ext in
              z)        filt=unpack ;;
              Z)        filt=uncompress ;;
              gz)       filt=gunzip ;;
              bz2)      filt=bunzip2 ;;
              pgp)      filt='pgp -df' ;;
              tgz)      filt=gunzip format=tar ;;
              TAZ|taz)  filt=uncompress format=tar ;;
              arc|lzh)  format=lzh ;;
              uu)       format=uu ;;
              tar)      format=tar ;;
              cpio)     format=cpio ;;
              zip)      format=zip ;;
#             rpm)      format=rpm ;;
              *)        case $b in
                            cpiof*)     format=cpio ;;
                            tarf*)      format=tar ;;
                            *)          break ;;
                        esac
                        ;;
          esac

          [ -n "$filt" ] && { pipe="$pipe$pipeext $filt"
                              pipeext=" |"
                            }

          # figured the format - bail and handle it
          [ -n "$format" ] && break

          # backstep for next pass
          nth=`expr $nth - 1`
      done

      if [ -z "$format" ]
      then
          echo "$cmd: $f: unrecognised format" >&2
          exit 1
      else
          eval "formatfilter=\$${mode}_$format"
          pipe="$pipe$pipeext $formatfilter"
      fi

      [ $pageit ] && pipe="$pipe | less -E"

      eval "$pipe"
    ) || xit=1
done

exit $xit
------------------ SNIP HERE ----------------------------------------------
-- 
 http://www.netmeister.org/news/learn2quote.html
                                       ...'cause only lusers quote signatures!
     Thomas Ribbrock | http://www.ribbrock.org | ICQ#: 15839919
   "You have to live on the edge of reality - to make your dreams come true!"



-- 
redhat-list mailing list
unsubscribe mailto:redhat-list-request@;redhat.com?subject=unsubscribe
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to