#!/bin/sh

# Reverse.bash
# 2007-02-02
# Chieh Cheng
# http://www.CynosureX.com/

# GNU General Public LIcense (GPL), Version 2, June 1991

scriptName=`echo $0 | sed s/\\\\/.*\\\\///g`

if [ $# -lt 2 ]
then
  echo "  Usage:   $scriptName \"infile\" \"outfile\""
  exit
fi

infile="$1"
outfile="$2"

if [ -f "${outfile}" ]
then
  echo "${outfile} already exists."
else
  count=0
  for line in `cat "${infile}"`
  do
    lines[$count]="${line}"
    count=`expr ${count} + 1`
  done

  count=`expr ${count} - 1`
  while [ $count -ge 0 ]
  do
    echo "${lines[$count]}" >> "${outfile}"
    count=`expr ${count} - 1`
  done
fi
