Saturday, October 6, 2012

How to combine the files Vertically or Horizontally in Unix


########################################################
# Combine the files vertically or Horizontally                        ##
########################################################

#!/bin/ksh

# To make sure sufficient arguments
if [ $# -ne 2 ]
then
  echo "Please provide the two file names to be combine"
  exit -1
fi

# Initializing the local variables
file1=$1
file2=$2
Hori=/clocal/fme/prod/forecast/padu/Lilly/Horizontal.txt
verti=/clocal/fme/prod/forecast/padu/Lilly/Vertical.txt
echo "Please choose the combination format"
echo "1) Horizontal"
echo "2) Vertical"
read ch
case $ch in
1) cat $file1>$Hori
   cat $file2>>$Hori;;
2) paste $file1 $file2>$verti;;
*) ;;
esac
exit 0