#*****************************************************************************************************************
#*****************************************************************************************************************
#
# This file is called by the Script File_Validation_script.sh to validate the data feeds
# ---------------------------------------------------------------------------------------------------------------
#
$1 - Parameter file path
# $2 - Unified Parameter file name
# $3 - File name of which Header and Trailer record needs to be removed.Filename should be without extension.
# Default extension ".dat" is used
##############################################################################################
function exit_script
{
if [[ $1 -eq 0 ]]
then
out_msg="Script File_Validation_script.sh - ended successfully"
else
out_msg="Script File_Validation_script.sh - ended abnormally"
fi
write_log "$out_msg"
exit $1
} # exit_script
############################ MAIN SCRIPT STARTED ##################################################
#set -x
cat $2 | tr -ds "$" "" > File_Validation_script_$3.param_3
export `cat File_Validation_script_$3.param_3`
chmod 777 File_Validation_script_$3.param_3
cd $prmDirinterface
script_log=$prmDirJobLog/
rm -f File_Validation_script_$3.log
touch File_Validation_script_$3.log
write_log "Script File_Validation_script.sh $3 Started..."
infile=$prmDirinterface/$3
echo "Script File_Validation_script.sh is Executing"
$prmDirinterface/$3=
/data/datastage/landing/input/input_param_file
INPUT_FILE=${INFILE}
echo INFILE=${INFILE}
OUTFILE=${ICCMENV}/rawdata/pnx
echo OUTFILE=${OUTFILE}
namecheck
HEADER=`head -1 ${INFILE} | awk '{printf ("%s\n",substr($0,1,80))}'`
VALIDHEADER="HEADER"
if [[ "${HEADER}" != "${VALIDHEADER}" ]] then
echo "Invalid REC_TYPE for header record on file, Header REC_TYPE is ${HEADER}, should be ${VALIDHEADER}. Header Record either Missing or Invalid"
exit 4
fi
TRL=`tail -1 ${INFILE} | awk '{printf ("%s\n",substr($0,1,9))}'`
VALIDTRL="TRAILER"
if [[ "${TRL}" != "${VALIDTRL}" ]] then
echo "Invalid REC_TYPE for Trailer record on file, Trailer REC_TYPE is ${TRL}, should be ${VALIDTRL}. Trailer Record either Missing or Invalid"
exit 4
fi
HEADERDTFILE=`head -1 ${INFILE} | awk '{printf ("%s\n",substr($0,47,8))}'`
echo "The header DDMMYYYY value is: ${HEADERDTFILE}"
echo "The Order Date passed to the job is: ${ODATE}"
RUNDATE1=`echo ${ODATE} | awk '{printf ("%s\n",substr($0,1,8))}'`
HEADERDT=`head -1 ${INFILE} | awk '{printf ("%s\n",substr($0,53,2))}'`
echo 'the headePr day is' ${HEADERDT}
HEADERMTH=`head -1 ${INFILE} | awk '{printf ("%s\n",substr($0,51,2))}'`
echo 'the header month is' ${HEADERMTH}
HEADERYER=`head -1 ${INFILE} | awk '{printf ("%s\n",substr($0,47,4))}'`
echo 'the header year is' ${HEADERYER}
echo 'Order date is' ${ODATE}
RUNDT1=`echo ${ODATE} | awk '{printf ("%s",substr($0,7,2))}'`
echo 'the run day is' ${RUNDT1}
RUNMTH1=`echo ${ODATE} | awk '{printf ("%s",substr($0,5,2))}'`
echo 'the run month is' ${RUNMTH1}
RUNYEAR1=`echo ${ODATE}| awk '{printf ("%s",substr($0,1,4))}'`
echo 'the run year is' ${RUNYEAR1}
if [ "${HEADERDT}" != "${RUNDT1}" ] || [ "${HEADERMTH}" != "${RUNMTH1}" ] || [ "${HEADERYER}" != "${RUNYEAR1}" ]
then
echo "Invalid header date present on file "
exit 4
else
echo "The Header Date is valid"
fi
TRLCT1=`tail -1 ${INFILE} | awk '{printf ("%d",substr($0,53,7))}'`
echo "Trailer Count = ${TRLCT1}"
RECCNT1=`wc -l ${INFILE} | awk '{printf ("%d\n",($1)-2)}'`
echo "Record Count = ${RECCNT1}"
onecount
validate
echo "Removing Header and Trailor"
RECCNT=`wc -l ${INFILE} | awk '{printf ("%d\n",($1 -2))}'`
tail +2 ${INFILE} | head -${RECCNT} > ${OUTFILE}/${INPUT_FILE}
sum ${OUTFILE}/${INPUT_FILE} | awk '{print $1}' > ${OUTFILE}/tempfile
VALCOUNT=`cat tempfile | awk '{print $1}'`
mv ${OUTFILE}/${INPUT_FILE} ${OUTFILE}/${INPUT_FILE}_${VALCOUNT}.CSV
rm ${OUTFILE}/tempfile
if [ $? -ne 0 ] ; then
echo "Unable to move ${INFILE} to ${OUTFILE}"
exit 1
fi
echo "${OUTFILE} file successfully created.."
No comments:
Post a Comment