Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

Need help in comparing two files in UNIX with a mismatch

$
0
0
Hi Everyone,
I am comparing results of two environments using unix files.

I am writing two different csv file using spool and merging both the files using paste command

paste -d, file1.csv file2.csv > prod_uat_result.csv

and then finding the difference and attaching the same in a mail

Code:

cat prod_uat_result.csv |awk -F"," '{print $1,",",$2,",",$3,",",$4,",",$5,",",$6,",",$7,",",$8,",",$9,",",$10,",",$11,",",$12
,",",$13,",",$14,",",$15,",",$16,",",$17,",",$6-$14}' > prod_uat_result1.csv

uuencode prod_uat_result1.csv prod_uat_result1.csv > prod_uat_result1.txt

Under normal circumstances it is working fine.But if there is some record missing in file2.csv then it should skip the comparision.

ex
file1.csv
Code:

1,10
1,20
2,10
2,20
2,30
3,40
4,50

file2.csv
Code:

1,10
1,20
2,10
2,20
2,30
4,50

So,ideally (3,40) in file1.csv should not be compared with 4,50 of file2.csv to find the difference.

I have tried left outer join but it will not work out since there is no primary key,have also tried giving row number while writing to a file but that will also not compare the right results.

My requirement is, if row is not present in the second file (file2.csv) then the comparison should be skipped and compare next row.

Could you please help me with this

Viewing all articles
Browse latest Browse all 16232

Latest Images

Trending Articles



Latest Images