Parsing files depending on the content

I am trying to parse files kkapjil kkpcjil kkexjil ...which have autosys job names. The objective is to parse each file...do an autorep -j <job name > -q and write it as output with a line for condition at the end of the each job. The problem I am facing is with the box jobs...as autorep -j <box name> -q would also list the child jobs and the condition would listed at the end of the last child job.

#*************************************
#more kkapjil
#+ more kkapjil
#testing_box.ttap0009
#testing_box.ttapbpo
#*************************************
#more kktcjil_cmd
#+ more kktcjil_cmd
##testing_cmd.tttc0001_1_ae_gprd8
##testing_cmd.tttc0125_ae
#testing_cmd.tttc0113_ae
#testing_cmd.tttc0118_ae
#testing_cmd.tttc0110_ae
#testing_cmd.tttc0111_ae
#testing_cmd.tttc0112_ae
#testing_cmd.tttc0119_ae
#testing_cmd.tttc0128_ae
#testing_cmd.tttc0120_ae
#testing_cmd.tttc0104_rb
#testing_cmd.tttc0109_sqr_4
#testing_cmd.tttc0126_ae
#testing_cmd.tttc0114_ae
#testing_cmd.tttc0117_ae
#testing_cmd.tttc0115_ae
#testing_cmd.tttc0116_ae
#testing_cmd.tttc0100_ae
#testing_cmd.tttc0121_ae
#testing_cmd.tttc0128_ae_2
#testing_cmd.tttc0120_ae_2
#testing_cmd.tttc0109_sqr_3
#testing_cmd.tttc0129_ae
#***************************************************
 
#set -A files kkapjil kkpcjil kkexjil kkgljil kkpojil kkpajil kktcjil kktrjil restjil kkapjil_cmd kkpcjil_cmd kkexjil_cmd 
#kkgljil_cmd kkpojil_cmd kkpajil_cmd kktcjil_cmd kktrjil_cmd restjil_cmd
set -A files kktcjil_cmd
rm kk*jil*.txt restjil*.txt
for term in ${files
[*]} # Read each file from the array
do
count=0
cat $term | while read LINE # Read the content of each file
do
let count++
autorep -j $LINE -w > test_ps #In order to use the temp file later to add the corressponding condition id
autorep -j $LINE -q > term1.txt # to handle box job we need a temp file
autorep -j $LINE -q >> $term.txt # Keep adding the jil to file for non box jobs
if [ $(grep -i "box:" term1.txt | wc -l) -gt 0 ]; then # handle box jobs
    touch boxjil
    cat term1.txt|while read LINE1; #Parse the box job
  do
    if [ "$LINE1" = "" ]; then #search the jil until it encounters a blank line
       echo $LINE1 >> test_test# write out until you encounter a blank line.
                               # This would give you only the box jil rather then all the child jobs
    fi
  done
    cat $term.txt test_test
fi
exit
if   [ $(grep "kkap" test_ps | wc -l) -gt 0 ]; then
  echo "condition: TTMGSW" >> $term.txt
elif [ $(grep "kkpc" test_ps | wc -l) -gt 0 ]; then
  echo "condition: TTMGT3 " >> $term.txt
elif [ $(grep "kkex" test_ps | wc -l) -gt 0 ]; then
  echo "condition: TTMGSV" >> $term.txt
elif [ $(grep "kkgl" test_ps | wc -l) -gt 0 ]; then
  echo "condition: TTMGSY" >> $term.txt
elif [ $(grep "kkpo" test_ps | wc -l) -gt 0 ]; then
  echo "condition: TTMGSZ " >> $term.txt
elif [ $(grep "kkpa" test_ps | wc -l) -gt 0 ]; then
  echo "condition: TTGNH4" >> $term.txt
elif [ $(grep "kktc" test_ps | wc -l) -gt 0 ]; then
  echo "condition: TTMGT4" >> $term.txt
elif [ $(grep "kktr" test_ps | wc -l) -gt 0 ]; then
  echo "condition: TTMGT4" >> $term.txt
else
  echo "condition: " >> $term.txt
fi
done
done
echo -e "\nTotal $count Lines read"

---------- Post updated at 11:59 AM ---------- Previous update was at 11:13 AM ----------

There is some problem with the logic in this section (read the box jil and print till it finds the first new line.

if [ $(grep -i "box:" term1.txt | wc -l) -gt 0 ]; then # handle box jobs
    cat term1.txt|while read LINE1; #Parse the box job
  do
    if [ "$LINE1" = "" ]; then #search the jil until it encounters a blank line
       echo $LINE1 >> test_test# write out until you encounter a blank line.This would give you only the box jil rather then all the child jobs
    fi
  done
    mv test_test $term.txt
else
autorep -j $LINE -q >> $term.txt # Keep adding the jil to file for non box jobs
fi

---------- Post updated at 12:50 PM ---------- Previous update was at 11:59 AM ----------

I have been able to devise a solution..Pls ignore this request..Thanks