Sponsored Content
Full Discussion: comparing two tables
Top Forums Shell Programming and Scripting comparing two tables Post 302231313 by akil on Tuesday 2nd of September 2008 05:29:32 AM
Old 09-02-2008
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
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Converting tables of row data into columns of tables

I am trying to transpose tables listed in the format into format. Any help would be greatly appreciated. Input: test_data_1 1 2 90% 4 3 91% 5 4 90% 6 5 90% 9 6 90% test_data_2 3 5 92% 5 4 92% 7 3 93% 9 2 92% 1 1 92% ... Output:... (7 Replies)
Discussion started by: justthisguy
7 Replies

2. Shell Programming and Scripting

tables in scripts

Hi , I have two tables with same length t1 and t2, I want to cretae a new third table where i put the difference between the elements of t2 and t1, t3= t1 - t2 t3= t1 - t2 I am new to scripts, any help please? thanks (7 Replies)
Discussion started by: Celine19
7 Replies

3. Shell Programming and Scripting

Comparing rows in two tables and sending the differnce to mail

Hi, I have a table ,containg 2 coloumns and many rows,which is updated everyday.The no.of rows in the table changes everyday. i have to write the difference between yesterdays tabtle and todays table to a new file.The row that is new in the todays table need not to be shown.only the change... (2 Replies)
Discussion started by: bab123
2 Replies

4. Shell Programming and Scripting

Tables and borders

when i do this: cat HITS i get the following displayed: sport.hits:87.114.172.31 Thu Sep 28 22:45:12 GMT 2006 how do i put this information into a bordered table? so it will output like this: ...........File /... (9 Replies)
Discussion started by: amatuer_lee_3
9 Replies

5. Shell Programming and Scripting

Shell script for comparing data of tables

Hi, I have two databases with same tables on different servers.I need to check the data content in each table and if something is missing, should print that. I have a tool which takes the snapshot the table structure,index so on and compares with the other server tables snapshot. Now i need... (1 Reply)
Discussion started by: nessj
1 Replies

6. Shell Programming and Scripting

Show only new and removed records by comparing to MySQL tables

Hello all; I have been really frustrated with finding the correct perl code (and MySql statements) to accomplish what I thought was straight forward...I have tested I don't know how many different codes\suggestions I found on the net without any success...but anyhow let me explain my plight and... (0 Replies)
Discussion started by: gvolpini
0 Replies

7. Shell Programming and Scripting

Selecting tables

Hi, Can anyone help me that, How to see the table fields in Oracle database through shell script(ksh). I have tried with the following: sqlplus -s $user/$passwd@$sid << SQL >> session.log select * from Testtab.sql I'm not able to see anything.. Thanks (4 Replies)
Discussion started by: zxcjggu708
4 Replies

8. Shell Programming and Scripting

UPDATE COmmand post comparing 2 columns in 2 mysql tables

my queryis : select distinct m.name, item_count, item from master m join client p on m.name=p.name where item_count = 1 and item > 1; But how should I update them? i used update statetment : Update from client Set item =1 where m.name=p.name and item_count=1 AND item>1 Is this wrong? (1 Reply)
Discussion started by: siya@
1 Replies

9. Shell Programming and Scripting

Comparing two tables

I have defined a set of global variables at the beginning of my script as below: #ideal values export ITEM1=SUCCESS export ITEM2=FAILURE export ITEM3=UNAVAILABLE export ITEM5=FAILURE export ITEM6=SUCCESS now I have a shell script function which returns a value in below format. ITEM1... (1 Reply)
Discussion started by: ctrld
1 Replies

10. Shell Programming and Scripting

Compare with 2 tables

I have 3 file inputs, file1 20160302|5485368299953|96|510101223440252|USA|5485368299953|6|800|2300|0 20160530|5481379883742|7|510101242850814|USA|5481379883742|5|540|2181|1500 20160513|5481279653404|24|510100412142433|INDIA|5481279653404|3|380|1900|0... (1 Reply)
Discussion started by: radius
1 Replies
ALTER 
VIEW(7) PostgreSQL 9.2.7 Documentation ALTER VIEW(7) NAME
ALTER_VIEW - change the definition of a view SYNOPSIS
ALTER VIEW [ IF EXISTS ] name ALTER [ COLUMN ] column_name SET DEFAULT expression ALTER VIEW [ IF EXISTS ] name ALTER [ COLUMN ] column_name DROP DEFAULT ALTER VIEW [ IF EXISTS ] name OWNER TO new_owner ALTER VIEW [ IF EXISTS ] name RENAME TO new_name ALTER VIEW [ IF EXISTS ] name SET SCHEMA new_schema ALTER VIEW [ IF EXISTS ] name SET ( view_option_name [= view_option_value] [, ... ] ) ALTER VIEW [ IF EXISTS ] name RESET ( view_option_name [, ... ] ) DESCRIPTION
ALTER VIEW changes various auxiliary properties of a view. (If you want to modify the view's defining query, use CREATE OR REPLACE VIEW.) You must own the view to use ALTER VIEW. To change a view's schema, you must also have CREATE privilege on the new schema. To alter the owner, you must also be a direct or indirect member of the new owning role, and that role must have CREATE privilege on the view's schema. (These restrictions enforce that altering the owner doesn't do anything you couldn't do by dropping and recreating the view. However, a superuser can alter ownership of any view anyway.) PARAMETERS
name The name (optionally schema-qualified) of an existing view. IF EXISTS Do not throw an error if the view does not exist. A notice is issued in this case. SET/DROP DEFAULT These forms set or remove the default value for a column. A default value associated with a view column is inserted into INSERT statements on the view before the view's ON INSERT rule is applied, if the INSERT does not specify a value for the column. new_owner The user name of the new owner of the view. new_name The new name for the view. new_schema The new schema for the view. view_option_name The name of a view option to be set or reset. view_option_value The new value for a view option. NOTES
For historical reasons, ALTER TABLE can be used with views too; but the only variants of ALTER TABLE that are allowed with views are equivalent to the ones shown above. EXAMPLES
To rename the view foo to bar: ALTER VIEW foo RENAME TO bar; COMPATIBILITY
ALTER VIEW is a PostgreSQL extension of the SQL standard. SEE ALSO
CREATE VIEW (CREATE_VIEW(7)), DROP VIEW (DROP_VIEW(7)) PostgreSQL 9.2.7 2014-02-17 ALTER VIEW(7)
All times are GMT -4. The time now is 02:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy