Friday, November 12, 2010

Merge Two Files - Scripts

#!/bin/ksh

echo 'Merge Script is Start'

OutputFileName_Data=/home/postings_data.dat
OutputFileName_Trailer=/home/postings_Trailer_AS.dat
OutputFileName=/home/postings.dat

rm -f $OutputFileName

test -s $OutputFileName_Data
if [ $? = 1 ] ; then
echo " file size equal to 0" ;
echo " Default Header is Processing ";

test='HEADER EMPTY'
echo $test
HEADER='HDR'
#JOURNAL_ID=' '
#RUN_DATE_TIME=date '+%Y-%m-%d %H:%M'
ROW_COUNT='0000001'
DEBIT='00000000000000000'
CREDIT='00000000000000000'
JRLN_EFF_DT='0000000000'

echo $HEADER$' '$(date '+%Y-%m-%d %H:%M')$ROW_COUNT$DEBIT$CREDIT$JRLN_EFF_DT > $OutputFileName

error_status=$?

if [ $error_status -ne 0 ]
then
echo " Default Header is Processed with Error"
exit 1
else

echo " Default Header is Process Successfully";

rm -f /home/postings_data.dat
rm -f /home/postings_Trailer.dat

fi

else
echo " File Having Data : $OutputFileName_Data & size greater than 0" ;

error_status=0

cat $OutputFileName_Data $OutputFileName_Trailer >$OutputFileName

error_status=$?

if [ $error_status -ne 0 ]
then
echo "mergewith_Trailer.ksh:Error while writing the file1 to : $OutputFileName"
exit 1
else
echo "mergewith_Trailer.ksh:Success while writing the file to : $OutputFileName"

rm -f /home/postings_data.dat
rm -f /home/postings_Trailer.dat
fi

fi

No comments: