I am pasting the code that I am using .
I am trying to get ddl based on table names passed in table.lst file .
I am doing 2 things here.
a) Changing tablespace name to _S02 . ( Thanks for the help on that )
b) Adding VW as prefix to all the view names .
I have written error part in the section where I get the error .
I get error on adding VW section.
It works fine for tablespace name add . But doesn't change the View name.
i.e. view name = DAYA.DIM_DATE
DESIRED OUTPUT I WANT IS LIKE THIS
DAYA.VW_DIM_DATE
#!/bin/ksh
USAGE='USAGE: miglook.shl [Source_DBNAME-required] [Source_Schema] [Target_Schema]'
if [[ $# -lt 3 ]]; then
clear
echo "\nIncorrect usage!!\n"
echo "Script was invoked last time as: miglook.shl $"
echo "\nThe correct usage is:\n"
echo "$USAGE"
echo "\n********************************************************************************************************************************************"
echo "Arguments:"
echo "Source_DBNAME i.e. Name of database from which to extract DDL"
echo "Source_Schema i.e. Name of schema from which objects DDL need to be extracted"
echo "Target_Schema i.e. Name of schema for which DDL need to be created\n"
echo "*********************************************************************************************************************************************\n"
exit
fi
dbname=$1
source_schema=$2
target_schema=$3
typeset -u dbname
tmpfile_tab=/tmp/tmpfile_tab
tmpfile_dep=/tmp/tmpfile_tab_dep
tmpfile_cln=/tmp/tmpfile_cln
ecmdate=`date +%Y%m%d`
db2 connect to $dbname
if [ $2 ]
then
source_schema=$2
else
source_schema='UHCDM001'
fi
if [ $3 ]
then
target_schema=$3
else
target_schema=${source_schema}
fi
typeset -u source_schema
typeset -u target_schema
cat table.lst | \
while read TN
do
#############################################################################################################################################################
# convert the table name read to lowercase to statdardise for tkt name.
#############################################################################################################################################################
typeset -l TN
#############################################################################################################################################################
# Create list of dependent objects for base table
#############################################################################################################################################################
echo $TN > ${tmpfile_tab}$TN
db2 -x "select tabname from syscat.tabdep where bschema=upper('${source_schema}') and bname=upper('$TN') and btype in ('T','V','S') " > ${tmpfile_dep}$TN
cat ${tmpfile_dep}$TN | while read line
do
db2 -x "select tabname from syscat.tabdep where bschema=upper('${source_schema}') and bname=upper('$line') and btype in ('T','V','S') " >> ${tmpfile_dep}$TN
done
cat ${tmpfile_dep}$TN >> ${tmpfile_tab}$TN
#############################################################################################################################################################
# Extracting DDL for base table and its dependent dependent objects along with their grants.
#############################################################################################################################################################
cat ${tmpfile_tab}_$TN | while read tname
do
db2look -d ${dbname} -z ${source_schema} -t ${tname} -e -x >> $TN.${ecmdate}.sql
cat $TN.${ecmdate}.sql | tr a-z A-Z > $TN.${ecmdate}.sql
done
############################################################################################################################################################
# Cleaning the table
#############################################################################################################################################################
cat $TN.$\{ecmdate\}.sql |egrep -v "^--|^$|CONNECT|COMMIT|TERMINATE" > $tmpfile_cln
cat $tmpfile_cln |egrep -v "SET CURRENT" > $TN.$\{ecmdate\}.sql
echo "CONNECT TO $dbname ;" > $tmpfile_cln
echo "SET SESSION_USER $target_schema ;" >> $tmpfile_cln
echo "SET CURRENT SCHEMA $target_schema ; " >> $tmpfile_cln
cat $TN.$\{ecmdate\}.sql >> $tmpfile_cln
echo "COMMIT WORK ; " >> $tmpfile_cln
echo "CONNECT RESET ; " >> $tmpfile_cln
echo "TERMINATE ; " >> $tmpfile_cln
#############################################################################################################################################################
# If moving same set of tables from one schema to other schema in same datebase then rename schema correctly
#############################################################################################################################################################
if [[ $\{source_schema\} != $\{target_schema\} ]]; then
cat $tmpfile_cln | sed -e 's/'$\{source\_schema\}'/'$\{target_schema\}'/g' > $TN.$\{ecmdate\}.sql
typeset -l source_schema
typeset -l target_schema
\# cat $TN.$\{ecmdate\}.sql1 > $TN.$\{ecmdate\}.sql
cat $TN.$\{ecmdate\}.sql | sed -e 's/'$\{source\_schema\}'/'$\{target_schema\}'/g' > $tmpfile_cln
cat $TN.$\{ecmdate\}.sql > $tmpfile_cln
sed -e 's/\\\(TEST[^"]*\\\)/\\1_S02/g' $tmpfile_cln > $TN.$\{ecmdate\}.sql
##############################################################################
#checks if the file has view in it ADD VW_ TO VIEW NAME (ERROR PART )
#############################################################################
grep -iq 'view' $TN.${ecmdate}.sql
if [ $? -eq 0 ]
then
VW_VAR=` cat $TN.${ecmdate}.sql | grep -i view | awk '{print $3}' | cut -d '.' -f2 `
echo " VW_$VW_VAR "
sed -e 's/'${VW_VAR}'/VW_'${VW_VAR}'/g' $TN.${ecmdate}.sql > $tmpfile_cln
else
cat $TN.${ecmdate}.sql > $tmpfile_cln
fi
$tmpfile_cln > $TN.${ecmdate}.sql
################################################################################################
\#cat $TN.$\{ecmdate\}.sql
typeset -u source_schema
typeset -u target_schema
fi
############################################################################################################################################
# Cleaning up old files
#############################################################################################################################################################
rm $\{tmpfile\_tab\}_$TN
rm $\{tmpfile\_dep\}_$TN
rm $tmpfile_cln
done
db2 terminate
any help is appreciated .
Thanks a lot in advance !