Compare two files and show the mismatch columns


 
Thread Tools Search this Thread
Operating Systems AIX Compare two files and show the mismatch columns
# 1  
Old 01-24-2016
Question Compare two files and show the mismatch columns

I need to compare two files and find the mismatch columns in it for csv and fixed
width file.
Eg:
file1
Code:
c1,c2,c3,c4<----columnname
1,a,4,d
2,b,5,e
3,c,6,f

file2
Code:
c1,c2,c3,c4<----columnname
3,x,7,f
2,y,8,e
1,z,9,d

output
Code:
c2,c3<---- mismatch columname
a,4    x,7
b,5 or y,8 Ok with any values but i need mismatched columnnames.
c,6     z,9

1).In real time column length is high so how to sort column wise
2).how to find mismatch columns.

Any answers??

Last edited by Don Cragun; 01-24-2016 at 04:30 PM.. Reason: Add CODE tags.
# 2  
Old 01-24-2016
Is this a homework assignment?

What have you tried to solve this problem?

What operating system and shell are you using?

Are the header lines the same in both files? Or, can some columnames appear in a different order or not appear at all in one of the files?

I don't understand your question about sorting??? When you are comparing values line by line (as shown in your example) what would you sort?

Are you saying that every line will have a different value between the two files for every line if any line (other than the headers) has a mismatch in a given column?

No, I don't have any answers. I can't figure out what you're trying to do.

What do you mean by the comment: "Ok with any values but i need mismatched columnnames." If you don't care about the values, why print them?
# 3  
Old 01-24-2016
No i faced this scenario while validating 2 big files. Size is around 1.5 gb each.

I tried to sort each column at a time and cutted 1st few rows and tried to find the mismatch column. It taking to much of time.

I am using AIX nd shell s ksh.

Header lines are same in both files but sometime i should face files without header.(objective is to find mismatch column no.)

Values differ in few lines.

The scenario i am facing is should compare two files and find in which column records mismatching and should justify the reason so i need find the column names.

---------- Post updated at 03:03 AM ---------- Previous update was at 02:56 AM ----------

If i found the columname i will sort it out easily by job design in ETl tool.
# 4  
Old 01-25-2016
Not clear. A few more questions:
- How are the rows identified? If by row No., all the rows in your sample should show up in the result.
- What does "If i found the columname i will sort it out easily by job design in ETl tool" mean?
- What does "In real time column length is high so how to sort column wise" mean?
- Does "Header lines are same in both files but sometime i should face files without header.(objective is to find mismatch column no.) " mean: The columns' order is always identical? So we don't need the headers and could just use the col No.s?
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 2 files and show count same content.

$ cat File1 Non HTTP response code:java.net.ConnectException225073X 000000005143329Load time: 402335410224 Non HTTP response code: ava.net.ConnectException206423X 000000005143330Load time: 402305687161 Non HTTP response code: ava.net.ConnectException290212X 000000005143331Load time:... (1 Reply)
Discussion started by: ooilinlove
1 Replies

3. UNIX for Dummies Questions & Answers

Compare Columns in two files

Hi all, I would like to compare a column in one file to a column in another file and when there is a match it prints the first column and the corresponding second column. Example File1 ABA ABC ABE ABF File 2 ABA 123 ABB 124 ABD 125 ABC 126 So what I would like printed to a file... (0 Replies)
Discussion started by: pcg
0 Replies

4. Shell Programming and Scripting

Compare selected columns of two files and print whole line with mismatch

hi! i researched about comparing two columns here and got an answer. but after examining my two files, i found out that the first columns of the two files are not unique with each other. all i want to compare is the 2nd and 3rd column. FILE 1: ABS 456 315 EBS 923 163 JYQ3 654 237 FILE 2:... (1 Reply)
Discussion started by: engr.jay
1 Replies

5. Shell Programming and Scripting

Compare two files and mismatch report

Hi I have two files f1 and f2 and comma separated file. I need to comapre two files by field by field and not by whole line. If they match then skip the line from both the files. If they don't match write the mismatch record from f1 to f3. Assume both the files are sorted on first field. ... (5 Replies)
Discussion started by: dgmm
5 Replies

6. Shell Programming and Scripting

Compare two text files and Only show the differences

Hi experts, I'mvery new to shell scripting and learning it now currently i am having a problem which may look easy to u :) i have two files File 1: Start :Thu Nov 19 10:33:09 2009 ABCDGFSDJ.txt APDemoNew.ppt APDemoOutline.doc ARDemoNew.ppt ARDemoOutline.doc File 2: Start... (10 Replies)
Discussion started by: CelvinSaran
10 Replies

7. Shell Programming and Scripting

How to compare 2 files & get only few columns based on a condition related to both files?

Hiiiii friends I have 2 files which contains huge data & few lines of it are as shown below File1: b.dat(which has 21 columns) SSR 1976 8 12 13 10 44.00 39.0700 70.7800 7.0 0 0.00 0 2.78 0.00 0.00 0 0.00 2.78 0 NULL ISC 1976 8 12 22 32 37.39 36.2942 70.7338... (6 Replies)
Discussion started by: reva
6 Replies

8. Shell Programming and Scripting

How to compare two columns in two files?

Hello all, Could someone please let me know shell script or awk solution to compare two columns in two files? Here is the sample - file1.txt abc/xyz,M1234 ddd/lyg,M2345 cnn/tnt,G0123 file2.txt A,abc/xyz,kk,dd,zz,DCT,G0123,1 A,ddd/lyg,kk,dd,zz,DCT,M1234,1... (17 Replies)
Discussion started by: sncoupons
17 Replies

9. Shell Programming and Scripting

Edited: compare two files and print mismatch

Using unix shell script, how to compare two files and print lines with mismatch? Below are the requirements: 1. The number of lines on the two files is not the same. 2. The difference/mismatch can be found on the second or third column. 3. The comparison is not between line 1 of file 1 and line... (16 Replies)
Discussion started by: kingpeejay
16 Replies

10. Shell Programming and Scripting

compare three files and insert a blank line at each mismatch

i need to compare three files in unix a.txt b.txt c.txt 1 2 1 2 5 3 4 6 5 5 6 6 i need to insert a blank line in the file if i don't find a match and put the items at the same column if found a match The items in the files... (4 Replies)
Discussion started by: mad_man12
4 Replies
Login or Register to Ask a Question