Parser

Hi All,
I am trying to create a parser to find out what cobol programs are being called by which JCL's.

I need to search recursively until the main cobol program is found being called by a JCL.

I tried to create a script but I am not able to generalize it. Can someone please help.

#!/usr/bin/sh
set -x
#Create a parser to get the flow of cobol programs until it is being called from a JCL.

export search_dir_cob="/TAHPLIB/CBSRC/"
export search_dir_jcl="/TAHPLIB/PROD/"
jcl_call=true
#cob_prog=CFCS1311
#cob_prog=CLCSS540
export cob_prog=$1

#Replace the 4th character of source with O, to search for the object code being called into the JCL.
obj_code_1=`echo $cob_prog | awk -v pos=4 -v repl=O '{print substr($0,1,pos-1) repl substr($0,pos+1)}'`
grep "RUN $obj_code_1.PROG" ${search_dir_jcl}* 2>/dev/null > tst



#if length of jcl file is greater than 1 stop the search
#put that code later

count=`grep -F 'CALL "'$cob_prog'"' ${search_dir_cob}* | wc -l`
grep -F 'CALL "'$cob_prog'"' ${search_dir_cob}* > cob_search
cat cob_search | cut -d ":" -f1 | cut -d "/" -f4 | cut -d "." -f1 > cob_search1


for i in `cat cob_search1`
do
echo $i | awk -v pos=4 -v repl=O '{print substr($0,1,pos-1) repl substr($0,pos+1)}' | uniq >> cob_search2
done

for i in `cat cob_search2`
do
echo $i | grep "RUN $i.PROG" ${search_dir_jcl}* 2>/dev/null >> tst
done


Would you be so kind as to post some JCL samples?