Finding alternative code

Hi Sir's

I've the below piece of code has the following functionalities:

1) Read the "pcp" file and create Job related parameter file "$PARMFILE".
$PARMFILE has below variables:
AFTD2010 "FILE_TYPE_D=Y export FILE_TYPE_D"
AFTD2010 "FILE_TYPE_I=N export FILE_TYPE_I"
AFTD2010 "FILE_TYPE_S=Y export FILE_TYPE_S"

2) Execute $PARMFILE and remove.

3) Go to the $CTM_FILEDIR location to create temporary files.

4) check for the files type variables $FILE_TYPE_S, $FILE_TYPE_I and $FILE_TYPE_D. If the values for these variables are declared as "Y" then select the appropriate filenames "rubys*_$CTM_ODATE" , "rubyi*_$CTM_ODATE" and "rubyd*_$CTM_ODATE" from the location "$CTM_FTPOUT/" using the command "ls -1".
Condition is, for each file type there should be atleast one file.
example for filenames: "rubys1_20080202", "rubyd8_20080202",
"rubyi22_20080202" etc..

5) Finally I've to put all these file names into single files as "total_arrived_files".

I've written the below code to accomplish this. But are there any other better way to do the same task using "AWK" or "NAWK" by reducing the number of coding lines. ?

##########################################
pcp ${CTM_JOBNAME}$1 $CTM_ODATE > $PARMFILE
. $PARMFILE
rm -f $PARMFILE

cd $CTM_FILEDIR

if [ "$FILE_TYPE_S" == "Y" ]; then
ls -1 $CTM_FTPOUT/rubys*_$CTM_ODATE >> arrived_s_files
if [ $(awk 'END{print NR}' arrived_s_files) -eq "0" ]; then
exit 1
fi
fi

if [ "$FILE_TYPE_I" == "Y" ]; then
ls -1 $CTM_FTPOUT/rubyi*_$CTM_ODATE >> arrived_i_files
if [ $(awk 'END{print NR}' arrived_i_files) -eq "0" ]; then
exit 2
fi
fi

if [ "$FILE_TYPE_D" == "Y" ]; then
ls -1 $CTM_FTPOUT/rubyd*_$CTM_ODATE >> arrived_d_files
if [ $(awk 'END{print NR}' arrived_d_files) -eq "0" ]; then
exit 3
fi
fi

cat arrived_s_files arrived_i_files arrived_d_files > total_arrived_files
##########################################

Thanks in advance / Lokesha