#!/bin/sh
#
# print first -n lines (default 1) if -n not specified and
# pass the remainder through the program and args specified as $*
#
# Usage: 	tx [-n #lines] program [args]
# Example: 	ps | tx sort 			# sort a ps listing
#          	ps aux | tx grep bash           # ps show only bash processes
#
# Author: Corey Satten, corey @ cac.washington.edu, 1/11/92
# http://staff.washington.edu/corey
#
Usage="$0: [-n #lines] program [args]"
case "$1/$#" in
     */0)	echo "$Usage" 1>&2; exit 1;;
    -n/[12])	echo "$Usage" 1>&2; exit 1;;
    -n/*)	headlines="${2-1}"; shift; shift;;
   -n*/*)	echo "$Usage" 1>&2; exit 1;;
esac
# without the cat, some lines are read twice if input is a file, a sh bug?
cat - | (
    old_IFS="$IFS"				# some shells need this
    case "$headlines" in
	''|1)	IFS=; read title; echo "$title"
		;;
	*)	while [ $headlines -gt 0 ] ;do
		    IFS=; read title; echo "$title"
		    headlines=`expr $headlines - 1`
		done
		;;
    esac
    IFS="$old_IFS"
    exec "$@"
    )
