#!/bin/bash

testZ="-z"

case $# in

2) if [ $1 == $testZ ]; then
       echo; echo "Usage: `basename $0` [-z] tar-filename filename-pattern"; echo; exit $E_BADARGS
   else
       tar -xvf $1 `tar -tf $1 | grep $2`
   fi
   ;;

3) if [ $1 == $testZ ]; then
       gunzip -c $2 | tar -xvf - `gunzip -c $2 | tar -tf - | grep $3`
   else
       echo; echo "Usage: `basename $0` [-z] tar-filename "; echo; exit $E_BADARGS
   fi
   ;;

*) echo; echo "Usage: `basename $0` [-z] tar-filename filename-pattern"; echo; exit $E_BADARGS;;
esac