#!/bin/sh # tac.sh # 20050515 PixEye@bigfoot.com Creation # tac is the opposite of cat # It displays lines of file in reverse order (starting from end to begin) nbps=1 # Number of wanted parameters (without options) cmd=`basename $0` # Command name usage="Usage: $cmd [-h]" # Help message: usage=$usage"\n\tDisplay this help message.\n" usage=$usage"\nUsage: $cmd [...]" usage=$usage"\n\t$cmd is the opposite of cat." usage=$usage"\n\tIt displays lines of file in reverse order" usage=$usage"\n\t (starting from end to begin)." if test `uname` != "HP-UX" ; then e="-e" ; fi # HP-UX echo case if [ $# -ne $nbps -o "$1" = "-h" ] ; then # Check parameters number echo $e $usage 1>&2 ; exit 2 # Display message help and exit fi tmp1="/tmp/$cmd.tmp" tmp2="/tmp/$cmd""2.tmp" while [ "$#" -ge 1 ] do file="$1" if test ! -r "$file" ; then # If the file in unreadable: echo $e "$cmd: \"$file\" cannot read that file!" 1>&2 ; exit 3 fi > "$tmp1" while read line do echo "$line" > "$tmp2" cat "$tmp1" >> "$tmp2" mv "$tmp2" "$tmp1" done < "$file" cat "$tmp1" rm -f "$tmp1" shift done exit 0 # Normal exit # Prefs for vim editing: vim:ts=8:sw=8:tw=80