Edited: compare two files and print mismatch


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Edited: compare two files and print mismatch
# 8  
Old 06-23-2009
Why dont you give it a try... I have given you the output, you just have to format it.
# 9  
Old 06-23-2009
I got it! I used the 'sort'. Thanks thanks!
# 10  
Old 06-23-2009
Great...
# 11  
Old 06-23-2009
Quote:
Originally Posted by kingpeejay
hi king! the code you gave me doesn't work..
it doesn't print the lines with difference though i am sure that there are lines that have mismatch on the two files.

Thanks!
Did you check content in file3 because I redirected output to file 3?
I tested the code with the inputs you have given and I could match your output also..

If you want the result to be printed on the screen then remove the "> file3" part from the code and run it..
# 12  
Old 06-24-2009
@ king kalyan: it worked! but i have to sort 1st. Thanks for the help
# 13  
Old 07-01-2009
Quote:
Originally Posted by rakeshawasthi
Is this what you want...
Code:
sort file1 > file1_tmp
sort file2 > file2_tmp
sdiff file1_tmp file2_tmp | grep '|'

output:
Code:
abc 123 678                                                     |  abc 124 678
ghi 789 234                                                     |  ghi 789 244

This code works in case of difference is found how about those records tht are missing that is also part of it right??
For Ex:

File1

abc 123 678
abc 112 111
xyz 100 000

File2

abc 123 678
abc 112 112

Output of above code will be:

abc 112 111 | abc 112 112

But Output shud be

abc 112 111 | abc 112 112
xyz 100 100 |

Please help with that code....... As xyz 100 100 is also a difference as it is missing in 2nd file....
# 14  
Old 07-01-2009
hmm...
that was limited to my understanding of king's problem.
You can very well Try... No, sorting, no formatting... Smilie
Code:
$ grep -v -f file1 file2
abc 112 112
$ grep -v -f file2 file1
abc 112 111
xyz 100 000

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Compare two files and print output

Hi All, i am trying to compare two files in Centos 6. F1: /tmp/d21 NAME="xvda" TYPE="disk" SIZE="40G" OWNER="root" GROUP="disk" MODE="brw-rw----" MOUNTPOINT="" NAME="xvda1" TYPE="part" SIZE="500M" OWNER="root" GROUP="disk" MODE="brw-rw----" MOUNTPOINT="/boot" NAME="xvda2" TYPE="part"... (2 Replies)
Discussion started by: balu1234
2 Replies

2. AIX

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 c1,c2,c3,c4<----columnname 1,a,4,d 2,b,5,e 3,c,6,f file2 c1,c2,c3,c4<----columnname 3,x,7,f 2,y,8,e 1,z,9,d output c2,c3<---- mismatch columname a,4 x,7 b,5 or y,8 Ok with... (3 Replies)
Discussion started by: sabzR
3 Replies

3. Shell Programming and Scripting

Compare two files and print list

Hi Gents, I have 2 files as seen below. File 1: 9 1020 10 1001 11 1001 12 1002 13 1003 14 1004 15 1004 File 2: 9 1000 11 1001 12 1002 13 1003 15 1004 (5 Replies)
Discussion started by: jiam912
5 Replies

4. Shell Programming and Scripting

Compare two files and print using awk

I have 2 files: email_1.out 1 abc@yahoo.com 2 abc_1@yahoo.com 3 abc_2@yahoo.com data_1.out <tr> 1 MAIL # 1 TO src_1 </tr> <tr><td class="hcol">col_id</td> <td class="hcol">test_dt</td> <td class="hcol">user_type</td> <td class="hcol">ct</td></tr> <tr><td... (1 Reply)
Discussion started by: sol_nov
1 Replies

5. Shell Programming and Scripting

Compare columns 2 files and print

File 1 has 16 columns so does File 2 I want to remove all records from File 2 that column 1 and column 16 match between file 1 and file 2 delimter of files is ~ (10 Replies)
Discussion started by: sigh2010
10 Replies

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

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

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

9. Shell Programming and Scripting

compare two files and print the last row into first

suppose fileA vis vis gyh gye gyh fileB vis 23 gyh 21 gye 32 output shud be like in fileA ... vis 23 vis 23 gyh 21 gye 32 gyh 21 (1 Reply)
Discussion started by: cdfd123
1 Replies

10. Shell Programming and Scripting

to compare two files and to print the difference

suppose one file P1168S P2150L P85L Q597R R1097C Another file P2150L P85L Q597R R1097C R1379C R1587K Then output shud be R1379C R1587K thanks (5 Replies)
Discussion started by: cdfd123
5 Replies
Login or Register to Ask a Question