#!/bin/ksh
#
# $Revision: 1.7 $ $Date: 2012-07-26 17:11:49-04 $
# $Source: /home/vogelke/bin/RCS/tx,v $
# $Host: sys7.com $
# $UUID: 391e26e6-84d2-3df1-a72e-bd5190b96afb $
#
#<tx: extract a gzipped tar file
# usage: tx file [pattern-to-extract]

export PATH=/usr/local/bin:/bin:/usr/bin
tag="${0##*/}"

case "$#" in
    0)  echo "$tag: need a file"; exit 0 ;;
    *)  file="$1"; pat="$2" ;;
esac

case "$file" in
    *.tgz)     exec gunzip     -c "$file" | tar xvf - $pat ;;
    *.txz)     exec unxz       -c "$file" | tar xvf - $pat ;;
    *.bz2)     exec bunzip2    -c "$file" | tar xvf - $pat ;;
    *.tbz)     exec bunzip2    -c "$file" | tar xvf - $pat ;;
    *.pax.gz)  exec gunzip     -c "$file" | pax -rd -pe $pat ;;
    *.pax.xz)  exec unxz       -c "$file" | pax -rd -pe $pat ;;
    *.tar.gz)  exec gunzip     -c "$file" | tar xvf - $pat ;;
    *.tar.xz)  exec unxz       -c "$file" | tar xvf - $pat ;;
    *.tar.bz2) exec bunzip2    -c "$file" | tar xvf - $pat ;;
    *.tar.Z)   exec uncompress -c "$file" | tar xvf - $pat ;;
    *.pax)     exec pax -rd -pe < "$file" ;;
    *.zip)     exec unzip -a "$file" ;;
    *)         exec tar xvf $file $pat ;;
esac

exit 1     # should not get this far...
