Comparing the data in a 2 files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Comparing the data in a 2 files
# 1  
Old 11-19-2012
Question Comparing the data in a 2 files

Hi Friends,


I have a file 1

Code:
CREATE MULTISET TABLE TEYT_Q9_T.TEST ,NO FALLBACK ,
     NO BEFORE JOURNAL,
     NO AFTER JOURNAL,
     CHECKSUM = DEFAULT,
     DEFAULT MERGEBLOCKRATIO
     (
     XYZ DECIMAL(10,0),
      ABC VARCHAR(5) CHARACTER SET LATIN NOT CASESPECIFIC,
      PQR VARCHAR(20) CHARACTER SET LATIN NOT CASESPECIFIC,
     IST CHAR(4) CHARACTER SET LATIN NOT CASESPECIFIC,
      EFF_END_DT DATE FORMAT 'yyyy-mm-dd',
      EFF_STRT_DT DATE FORMAT 'yyyy-mm-dd',
      CRE_DT DATE FORMAT 'yyyy-mm-dd',
      CRE_BY VARCHAR(5) CHARACTER SET LATIN NOT CASESPECIFIC,
      ETL_PKG_ID DECIMAL(15,0) NOT NULL,
      SRC_SYS_CD VARCHAR(10) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL,
      CRE_RUN_ID INTEGER NOT NULL,
      ETL_SRC_FILE_NB DECIMAL(15,0) NOT NULL,
      ETL_ROW_NB INTEGER NOT NULL,
      ETL_FILE_TYPE_CD VARCHAR(1) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL DEFAULT 'I',
      ETL_LD_DT DATE FORMAT 'YYYY-MM-DD' NOT NULL,
      ETL_ACTN_CD CHAR(1) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL DEFAULT 'I' COMPRESS ('D','I','P','U'),
      ICDW_ISRT_TS TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP(0),
      BAD_RCRD_IND VARCHAR(1) CHARACTER SET LATIN NOT CASESPECIFIC)
PRIMARY INDEX NUPI_CST_MKEY_ORGN_MSTR ( ETL_PKG_ID ,CRE_RUN_ID ,
ETL_ROW_NB ,ETL_LD_DT );

File 2

Code:
 
record    
  decimal('Ç') xyz;         DECIMAL(10)  
  string('Ç') abc; VARCHAR(10)  
  string('Ç') pqr; VARCHAR(20)
  string("\307") ist; CHAR(4)  
  string('Ç') eff_end_dt; CHAR(8) YYYYMMDD
  string("\307") eff_strt_dt = NULL(""); CHAR(8) YYYYMMDD
  string("\307") cre_dt; CHAR(8) YYYYMMDD
  string("\n") cre_by;  VARCHAR(5)  
end

I need to validate the 2 files structures.Please find the green colour which i highlited where comparision sholud be done. Plz help

Output should Some thing like

Code:
 
Columnname | SOURCE_FILE1| TARGET_FILE2
abc             | varchar(5)     | varchar(10)


Last edited by i150371485; 11-19-2012 at 08:22 AM..
# 2  
Old 11-19-2012
I propose you a solution, maybe it is not the best one but you have to correct a bit of code but it works.

Code:
awk '$0 ~ /\(/, $0 ~ /PRIMARY/ {print $1,$2}' kk | while read var tipo
do 
otro=$(egrep -i "$var" kkk | cut -d";" -f2 | awk '{print $1}')
[[ ! -z $otro ]] && 
(
echo "VAR:$var, TIPO:$tipo, OTRO:$otro"
if [[ $tipo = $otro ]]
then 
echo "OK: var: $var, ok: $tipo vs $otro"
else 
echo "FAIL var: $var, ok: $tipo vs $otro"
fi
)
done

I hope It's usefull

---------- Post updated at 02:13 PM ---------- Previous update was at 02:06 PM ----------

I'm sorry, but file1 = kk and file2 = kkk, I was checking and I forget to correct it.
This User Gave Thanks to danielos For This Post:
# 3  
Old 11-23-2012
@danielos : Thanks for the reply. . I have tried the above code and will change accroding to my requirement.it would be great if you Could explain the code ?
# 4  
Old 11-23-2012
Hi!
Ok, I have fixed a bit of code:
Code:
#!/usr/bin/ksh

awk '$0 ~ /\(/, $0 ~ /PRIMARY/ {print $1,$2}' file1 | while read variable type_file1
do
   [[ "${variable}" = *[A-Za-z_] ]] &&
   (
      type_file2=$(egrep -i "$variable" file2 | cut -d";" -f2 | awk '{print $1}')
      [[ ! -z $type_file2 ]] &&
        (
        if [[ $type_file1 = $type_file2  ]]
        then
                echo "OK  : var: $variable,| FILE1: $type_file1 | FILE2: $type_file2"
        else
                echo "FAIL: var: $variable,| FILE1: $type_file1 | FILE2: $type_file2"
        fi
        )
    )
done

First I'm looking for two patterns in the file1 "(" and "PRIMARY", then print every line. I check the correct sintax of the $variable and I look for it into file2.
It can be improved, so if you do it tell me please
This is the output:
FAIL: var: XYZ,| FILE1: DECIMAL(10,0) | FILE2: DECIMAL(10)
FAIL: var: ABC,| FILE1: VARCHAR(5) | FILE2: VARCHAR(10)
OK : var: PQR,| FILE1: VARCHAR(20) | FILE2: VARCHAR(20)
OK : var: IST,| FILE1: CHAR(4) | FILE2: CHAR(4)
FAIL: var: EFF_END_DT,| FILE1: DATE | FILE2: CHAR(8)
FAIL: var: EFF_STRT_DT,| FILE1: DATE | FILE2: CHAR(8)
FAIL: var: CRE_DT,| FILE1: DATE | FILE2: CHAR(8)
OK : var: CRE_BY,| FILE1: VARCHAR(5) | FILE2: VARCHAR(5)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Comparing two files and list the difference with common first line content of both files

I have two file as given below which shows the ACL permissions of each file. I need to compare the source file with target file and list down the difference as specified below in required output. Can someone help me on this ? Source File ************* # file: /local/test_1 # owner: own #... (4 Replies)
Discussion started by: sarathy_a35
4 Replies

2. Shell Programming and Scripting

Comparing to 3 data

# cat list.txt server1 server2 server3 server4 # data to be compared of. #dns address 1.1.1.1 2.2.2.2 3.3.3.3 #for i in `cat list.txt` do grep dns $ i done (1 Reply)
Discussion started by: invinzin21
1 Replies

3. UNIX for Dummies Questions & Answers

Comparing lines of data

Total UNIX Rookie, but I'm learning. I have columns of integer data separated by spaces, and I'm using a Mac terminal. What I want to do: 1. Compare "line 1 column 2" (x) to "line 2 column 2" (y); is y-x>=100? 2. If yes, display difference and y's line number 3. If no, increment x and y by... (9 Replies)
Discussion started by: markymarkg123
9 Replies

4. UNIX for Advanced & Expert Users

How to find duplicates contents in a files by comparing other files?

Hi Guys , we have one directory ...in that directory all files will be set on each day.. files must have header ,contents ,footer.. i wants to compare the header,contents,footer ..if its same means display an error message as 'files contents same' (7 Replies)
Discussion started by: Venkatesh1
7 Replies

5. Shell Programming and Scripting

Comparing the matches in two files using awk when both files have their own field separators

I've two files with data like below: file1.txt: AAA,Apples,123 BBB,Bananas,124 CCC,Carrot,125 file2.txt: Store1|AAA|123|11 Store2|BBB|124|23 Store3|CCC|125|57 Store4|DDD|126|38 So,the field separator in file1.txt is a comma and in file2.txt,it is | Now,the output should be... (2 Replies)
Discussion started by: asyed
2 Replies

6. 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

7. Shell Programming and Scripting

Comparing data inside file

Hi Everyone, I will try to explain my question please forgive my english here. I am looking for shell script or command that can compare data in the files. I have 50 files in one directory test1 test2 test3 ....so on. I want to compare data in each files with each other and output each... (4 Replies)
Discussion started by: email-lalit
4 Replies

8. Shell Programming and Scripting

Comparing data in file with values in table

Hi, I want to calculate the number of pipe delimiters in a file for all lines seperately. For eg:i have a file Project.txt Mohit|chawla|123|678 File1|File2|345|767|678 And my file contains many lines like this it shd give me the output as 4 5 or give me the output for all the... (0 Replies)
Discussion started by: Mohit623
0 Replies

9. Shell Programming and Scripting

Problem comparing 2 files with lot of data

Hello everyone, here's the scenario I have two files, each one has around 1,300,000 lines and each line has a column (phone numbers). I have to get the phones that are in file1 but not in file2. I can get these phones trough Oracle but my boss does not want that so he gave me the files with the... (4 Replies)
Discussion started by: rafisha
4 Replies

10. UNIX for Dummies Questions & Answers

Comparing data list...

I have a list of files that I want to compare to another list of files, how do I do that? The first list will be my known list and hard coded, for example: mylist="janfile.tar jarfile.jar jan.rpt.Z" etc. The second list will be found by doing an 'ls' piped to a file: ls > filelist.dat ... (4 Replies)
Discussion started by: giannicello
4 Replies
Login or Register to Ask a Question