Compare data and columns script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare data and columns script
# 1  
Old 09-17-2010
Compare data and columns script

Hello all,
I have below SQLs to compare data between 2 identical tables.in my database.

Can any body help me to convert this into a script
Code:
db2 "select *from TAB1  where PK IN (select PK  from  TAB2) order by BEDG_NR".

Note:
These SQL should run for any given 2 tables as input TAB1 ,TAB2 and same primary key (PK).
This is db2 database

Last edited by Scott; 09-20-2010 at 07:40 AM.. Reason: Please use code tags
kanakaraju
# 2  
Old 09-17-2010
I am not sure about DB2, but you could use something like:
Code:
getCompareQuery ()
{
        firTab="${1}"
        secTab="${2}"
        pKey="${3}"
        orderBy="${4}"
        echo "select * from ${firTab} where ${pKey} IN (select ${pKey} from ${secTab}) order by ${orderBy}"
}

## Execute it as follow:
# getCompareQuery "TAB1" "TAB2" "PK" "BEDG_NR"
select *from TAB1 where PK IN (select PK from TAB2) order by BEDG_NR

# compQuery=`getCompareQuery "TAB1" "TAB2" "PK" "BEDG_NR"`
# db2 "${compQuery}"

Regards!

Last edited by felipe.vinturin; 09-17-2010 at 03:43 PM..
# 3  
Old 09-18-2010
compare data and columns script.

Hi ,
Thanks for the reply i have written like this and ran the script using below commands

Code:
$ ./cmpre.sh s1 tab1  tab2 PK ordkerkey 

ksh: ./cmpre.sh:  not found.
$
$ more cmpre.sh



$ more cmpre.sh
#!/usr/bash
#===========================
#Arguements Reading
#============================

schemaName="${1}"
firstTab= "${2}"
secondTab="${3}"
pKey="${4}"
orderBy="${5}"
db2 "set schema $schemaName"

#============================
#Execute Query as below
#CompareQuery "TAB1" "TAB2" "PK"
#============================

echo "db2 select count(*) from ${firTab} where ${pKey} NOT IN (select ${pKey} from ${secTab}) order by ${orderBy})"

Any one can tell why ksh has not recognized my script??

Last edited by Scott; 09-20-2010 at 07:41 AM.. Reason: Code tags...
kanakaraju
# 4  
Old 09-20-2010
Quote:
Originally Posted by kanakaraju
#!/usr/bash
Maybe because your path to the interpreter is wrong!

One of the following commands will help you find the correct path in your system:
Code:
# which bash
/bin/bash
# whereis bash
bash: /bin/bash /usr/share/man/man1/bash.1.gz

# 5  
Old 09-20-2010
compare data and columns script.

Hello felipe,

yes that script work for me and executed .thanks for ur support.

Regards
kanaka
kanakaraju
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare 2 csv files by columns, then extract certain columns of matcing rows

Hi all, I'm pretty much a newbie to UNIX. I would appreciate any help with UNIX coding on comparing two large csv files (greater than 10 GB in size), and output a file with matching columns. I want to compare file1 and file2 by 'id' and 'chain' columns, then extract exact matching rows'... (5 Replies)
Discussion started by: bkane3
5 Replies

2. Shell Programming and Scripting

Compare columns of two files and retrieve data

Hi guys, I need your help. I have two files: file1 1 3 5 file2 1,XX 2,AA 3,BB 4,CC 5,DD I would like to compare the first column and where they are equal to write that output in a new file: 1,XX 3,BB (7 Replies)
Discussion started by: apenkov
7 Replies

3. Shell Programming and Scripting

Howto compare the columns of 2 diff tables of 2 different schemas in UNIX shell script

HI All, I am new to Unix shell scripts.. Could you please post the unix shell script for for the below request., There are two different tables(sample1, sample2) in different schemas(s_schema1, s_schema2). Unix shell script to compare the columns of two different tables of two... (2 Replies)
Discussion started by: Rajkumar Gopal
2 Replies

4. Shell Programming and Scripting

awk based script to find the average of all the columns in a data file

Hi All, I need the modification for the below mentioned code (found in one more post https://www.unix.com/shell-programming-scripting/27161-script-generate-average-values.html) to find the average values for all the columns(but for a specific rows) and print the averages side by side. I have... (4 Replies)
Discussion started by: ks_reddy
4 Replies

5. Shell Programming and Scripting

Awk based script to find the median of all individual columns in a data file

Hi All, I have some data like below. Step1,Param1,Param2,Param3 1,2,3,4 2,3,4,5 2,4,5,6 3,0,1,2 3,0,0,0 3,2,1,3 ........ so on Where I need to find the median(arithmetic) of each column from Param1...to..Param3 for each set of Step1 values. (Sort each specific column, if the... (5 Replies)
Discussion started by: ks_reddy
5 Replies

6. Shell Programming and Scripting

script to compare two columns in a file

Dear everyone, I need any sort of shell script or perl script would do the following. I have a txt file as follows: ;Stretnumber Resident Resdient (not in file) 16 John Mary 16 Mary Parker 16 Nancy Smith 16 Mary John 18 Trey ... (5 Replies)
Discussion started by: sasharma
5 Replies

7. UNIX for Dummies Questions & Answers

How to compare two columns and retrieve data

I am a newbie to Unix and slowly learning it. I have a large data set with 8 different columns. I want to compare two columns and retrieve data if the two columns have similar number. I have attached the example. There are two columns (S-Contig and N-Contig). I want to retrieve the data from... (7 Replies)
Discussion started by: bjorngill
7 Replies

8. Ubuntu

How to compare two columns and fetch the common data with additional column

Dear All, I am new to this forum and please ignore my little knowledge :p I have two types of data (a subset is given below) data version 1: 439798 2 1 451209 1 2 508696 2 1 555760 2 1 582757 1 2 582889 1 2 691827... (2 Replies)
Discussion started by: evoll
2 Replies

9. Shell Programming and Scripting

help to compare data from file using shell script to c++ program

hello ....i am new in shell script..I have one shell script which read inputs from file...and second is c++ pgm..i call my script from c++ programm..to compare file values to c++ pgm value.. our shell script is shubhi.sh #! /bin/sh while read line do echo -e"$line" done<file1 this script... (1 Reply)
Discussion started by: shubhig15
1 Replies

10. Shell Programming and Scripting

Compare semicolon seperated data in 2 files using shell script

hello members, I have some data ( seperated by semicolon ) with close to 240 rows in a text file temp1. temp2.txt stores 204 rows of data ( seperated by semicolon ). I want to : Sort the data in both files by field1.i.e first data field in every row. compare the data in both files and print... (6 Replies)
Discussion started by: novice82
6 Replies
Login or Register to Ask a Question