Enhancing Script (using loops) to go through for each group

Currently I have written a shell script that will add departments for one group (displayed below with configuration file). I want to enhance the script in order to add departments to multiple groups by:

  1. Making changes to allow the script to loop through and write each dept/group combo into the DEPTFILE.

  2. After I get the dept list from the config file, check to see if the Group flag is on and if it is, then create a loop to go through for each group.

In the original configuration file, only one country was passed in (Brazil). Since then, I changed the variable to ${Cntry_code} (instead of just Brazil) and I added US in the config file.
Please let me know if anymore information is needed

Thanks in advance

Here is the script that I have currently:

bin/ksh

############################################################################
# Program: add_BING_group.sh
# Desc : this manually executed script will allow you to add a group
# and/or depts in BING
# Notes : To run this script pass in the country code.
# add_BING_group.sh <country_code>
# It uses addGroup.cfg to get the correct information to add
# Be sure that you make the correct changes in the cfg file before
# running the script
#
#################################################################

## checking a script call for the proper number of arguments
if [ "$#" -ne 1 ]
then
echo "USAGE: $0 <country_code>"
exit 0
fi

Cntry_code=$1
GROUP=`stanzaget addGroup.cfg ${Cntry_code} group`
BINGDB=`stanzaget addGroup.cfg ${Cntry_code} database`
GROUPFLAG=`stanzaget addGroup.cfg ${Cntry_code} addGroupFlag`
DEPTFLAG=`stanzaget addGroup.cfg ${Cntry_code} addDeptFlag`

dept_groupSQL="/tmp/dept_group.sql"
text_SQL="/tmp/groupText.sql"
DEPTFILE="/tmp/deptfile.unl"
DEPT_GRP_UNL="/tmp/dept_back.unl"

PATH=$PATH:$ITOOLSDIR/bin
`rm ${DEPTFILE}`
if [ ${GROUPFLAG} = "ON" ]
then
PLANG_CODE=`stanzaget addGroup.cfg ${Cntry_code} pri_lang_code`
PGRP_TXT=`stanzaget addGroup.cfg ${Cntry_code} pri_text`
SLANG_CODE=`stanzaget addGroup.cfg ${Cntry_code} sec_lang_code`
SGRP_TXT=`stanzaget addGroup.cfg ${Cntry_code} sec_text`

echo " Begin work; " > ${dept_groupSQL}
echo " insert into ${BINGDB}:dept_group values(${GROUP}); " >> ${dept_groupSQL}
echo " commit work; " >> ${dept_groupSQL}

echo " Begin work; " > ${text_SQL}
echo " insert into ${BINGDB}:dept_group_text values(${GROUP},${PLANG_CODE},'${PGRP_TXT}'); " >> ${text_SQL}
echo " insert into ${BINGDB}:dept_group_text values(${GROUP},${SLANG_CODE},'${SGRP_TXT}'); " >> ${text_SQL}

echo " insert into ${BINGDB}:dept_group_text values(10,103,'${TGRP_TXT}'); " >> ${text_SQL}

echo " commit work; " >> ${text_SQL}
dbaccess ${BINGDB} < ${dept_groupSQL}
echo "Loaded the group table"
dbaccess ${BINGDB} < ${text_SQL}
echo "Loaded the text table"

fi

if [ ${DEPTFLAG} = "ON" ]
then
DEPTLIST=`stanzaget addGroup.cfg ${Cntry_code} dept_list`

`iunload -d ${BINGDB} -t dept_dept_group -compress -isolation dirty ${DEPT_GRP_UNL}`

if [ ${DEPTLIST} = "ALL" ]
then
DEPTLIST=`stanzaget addGroup.cfg ${Cntry_code} dept_list_all`

for d in `echo $DEPTLIST | sed 's/,/ /g'`
do

 echo "$d|$\{GROUP\}|" &gt;&gt; $\{DEPTFILE\} 

done
fi

`iload -d ${BINGDB} -t dept_dept_group ${DEPTFILE}`

Fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Configuration File (addGroup.cfg)

US:
database = bingusa
group=0,1,2,3,4,5,6,7,8,9,10
group_text =
#addGroupFlag = OFF
addGroupFlag = ON
addDeptFlag = ON
dept_list=ALL
dept_list_all=0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,75,77,80,81,82,83,84,85,87,88,90,91,92,93,94,95,96,97,98,99

Brazil:
database = bingbrazil
group = 11
#group = 10
#addGroupFlag = OFF
addGroupFlag = ON
addDeptFlag = ON
pri_lang_code = 101
pri_text=FALL/WINTER
sec_lang_code = 103
sec_text=AUTOMNE/HIVER
third_text=Printemps/�t�
dept_list=ALL
dept_list_all=0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,75,77,80,81,82,83,84,85,87,88,90,91,92,93,94,95,96,97,98,99