Saturday, October 6, 2012

Reverse the content in the file using Unix


#####################################################
# Reverse the content in the file                                       ##
#####################################################

#!/bin/ksh

# To make sure the sufficient arguments
if [ $# -ne 1 ]
then
  echo "Please enter the file name to be reverse"
  exit -1
fi

# Implementation of logic to reverse the content in the file
if [ -f $1 ]
  then
    rever=`rev $1`
 echo "Original file is"
 cat $1
 echo "Reverse of the file is"
 echo $rever
fi

exit 0