comparing two tables

I am comparing two table structure in different databases,Put into 2 txt files , when comparing if column sequnce and data type is not matching ,it has to display that info else Table structure is ok.

wrote shell script ,its not working .I am getting "Table structure is not ok" even if both are in similar.

tab1=$1
tab2=$2

if [ ! -f $tab1 ] ; then
echo "file1 not exist:$tab1"
fi
if [ ! -f $tab2 ] ; then
echo "file2 not exist:$tab2"
fi
col1=`awk -F" " '/SET TABLE/{print substr($4,(index($4,".")+1))}1' $tab1 |egrep -iv 'create|journal|default|index'| sed -e
's/(//g' -e 's/)//g'|awk -F " " '{print $1 }'`

len1=`awk -F" " '/SET TABLE/{print $4}1' $tab1 |egrep -iv 'create|journal|default|index'|awk -F " " '{print $2 }'`

col2=`awk -F" " '/SET TABLE/{print substr($4,(index($4,".")+1))}1' $tab2 |egrep -iv 'create|journal|default|index'| awk -F
" " '{print $1 }'`

len2=`awk -F" " '/SET TABLE/{print $4}1' $tab2 |egrep -iv 'create|journal|default|index'| sed -e 's/(//g' -e 's/)//g'|awk -
F " " '{print $2 }'`

if [ "$col1"=="$col2" && "$len1"=="$len2" ]; then

echo "Table structure is ok"

else
echo "Table structure is not ok"
echo "$col1 $len1\n"
echo "$col2 $len2\n"
fi

Getting the below error message when calling the following script

ab.sh Tab1.txt Tab2.txt

ab.sh[18]: test: ] missing
Table structure is not ok

Tab1.txt
CREATE SET TABLE DB1.FACTOR_XX ,NO FALLBACK ,
NO BEFORE JOURNAL,
NO AFTER JOURNAL,
CHECKSUM = DEFAULT
(
Calculation_Factor_Cd CHAR(20) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL,
Calculation_Factor_Desc VARCHAR(250) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL,
Cd1 VARCHAR(20) CHARACTER SET LATIN NOT CASESPECIFIC,
Code1 VARCHAR(100) CHARACTER SET LATIN NOT CASESPECIFIC,
Start_Dt DATE FORMAT 'YYYY-MM-DD' NOT NULL
)
PRIMARY INDEX ( Calculation_Factor_Cd )
;

Tab2.txt

CREATE SET TABLE DB2.FACTOR_XX ,NO FALLBACK ,
NO BEFORE JOURNAL,
NO AFTER JOURNAL,
CHECKSUM = DEFAULT
(
Calculation_Factor_Cd CHAR(20) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL,
Calculation_Factor_Desc VARCHAR(250) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL,
Cd1 VARCHAR(20) CHARACTER SET LATIN NOT CASESPECIFIC,
Code1 VARCHAR(100) CHARACTER SET LATIN NOT CASESPECIFIC,
Start_Dt DATE FORMAT 'YYYY-MM-DD' NOT NULL
)
PRIMARY INDEX ( Calculation_Factor_Cd )
;

Thanks,
Akil

Replace this line:

if [ "$col1"=="$col2" && "$len1"=="$len2" ]; then

with:

if [ "$col1" == "$col2" -a "$len1" == "$len2" ]; then

With Bash you can use the extended testcommand with double brackets:

if [[ "$col1" == "$col2" && "$len1" == "$len2" ]; then

Regards