# Finding alternative code

**URL:** <https://community.unix.com/t/finding-alternative-code/184528>\
**Category:** UNIX for Advanced & Expert Users\
**Created:** [February 6, 2008, 1:45am UTC](https://community.unix.com/t/finding-alternative-code/184528 "2008-02-06T01:45:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lokesha](https://community.unix.com/letter_avatar/lokesha/32/5_5575768a8748004e209b776fc1b2916d.png) [@Lokesha](https://community.unix.com/u/Lokesha)\
**Post date:** [February 6, 2008, 1:45am UTC](https://community.unix.com/t/finding-alternative-code/184528/1 "2008-02-06T01:45:38Z")

</div>

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
