Comparision of two huge unix files - Reconcilation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Comparision of two huge unix files - Reconcilation
# 1  
Old 04-22-2011
Comparision of two huge unix files - Reconcilation

Hi,

I have two huge file; each one has approximately 150000 lines. I need to compare both of them and store the unmatched lines into a different file.

I have searched for everything in google but did not get solution.

Files are:
File1
Code:
NRALBAMINDB20003726
NRALBAMINDB20003727
NRALBAMINDB20003728

File2
Code:
NRALBAMINDB20003726
NRALBAMINDB20003727
NRALBAMINDB20003733

Output:
Code:
NRALBAMINDB20003728

I have tried the below query -
Code:
awk 'FILENAME=="File2" {arr[$0]++}
FILENAME=="File1" {If ($0 in arr) {continue}
else {print $0}}' File2 File1 >File3.txt

But its not working, output I am getting is - complete file1 gets pasted in File3 that is 'if part' is not getting executed.

One more thing, If i try the code with pretty less no of entries in File1 and File2 say 20 entries each, it works.

Thanks,
Suman.

Last edited by Franklin52; 04-22-2011 at 09:04 AM.. Reason: Please use code tags
# 2  
Old 04-22-2011
Welcome to the forum!

Since it is just 150000 lines, it is not huge.
Quote:
awk 'FNR==NR{a[$0]; next}!($0 in a)' File2 File1
# 3  
Old 04-22-2011
Code:
diff file1 file2 | grep '^<'|sed 's/^< //'

will be much faster
# 4  
Old 04-22-2011
Quote:
Originally Posted by pbillast
Code:
diff file1 file2 | grep '^<'|sed 's/^< //'

will be much faster
  1. assumes the files are sorted
  2. no need for the 'grep'
  3. timing comparisons?

Last edited by vgersh99; 04-22-2011 at 09:36 AM..
# 5  
Old 04-22-2011
Quote:
Originally Posted by pbillast
Code:
diff file1 file2 | grep '^<'|sed 's/^< //'

will be much faster
What makes you think this is much faster?
# 6  
Old 04-22-2011
If both files are sorted, then:
Code:
comm -23 file1 file2

# 7  
Old 04-22-2011
Thanks to every one.

But i just want to know why the code which i implemented did not work.



Thanks,
Suman
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Comparing Select Columns from two CSV files in UNIX and create a third file based on comparision

Hi , I want to compare first 3 columns of File A and File B and create a new file File C which will have all rows from File B and will include rows that are present in File A and not in File B based on First 3 column comparison. Thanks in advance for your help. File A A,B,C,45,46... (2 Replies)
Discussion started by: ady_koolz
2 Replies

2. Shell Programming and Scripting

Comparision of two text files

Dear all, I am having two files big files i need an output file as first occurance of file1 field in file2 example: file1:raju ranifile2:raju|123 raju|879 rani|623 rani|253result:raju|123 rani|623pls help me in this regard (3 Replies)
Discussion started by: suryanarayana
3 Replies

3. UNIX and Linux Applications

Unix Shell Scripting : Comparision of two files

Hi, We need to compare a text file File1.txt and config file File2.txt in a way that it checks if the content of File1.txt exists between the range mentioned in File2.cfg. The range here is the range between col1 and col2 of File2.cfg If the content of File1.txt lies between the range of... (12 Replies)
Discussion started by: CFA
12 Replies

4. Shell Programming and Scripting

Comparision of fields in 2 files.

Hi Experts, I have two huge files in the format as shown below.I need to open a file1 and file 2 , cut first 24 characters of file 1 and search if the key exists in file 2 first field (delimted by *). If the value exists , copy the third field from file 2 and replace the 5th field in file 1 .... (4 Replies)
Discussion started by: nua7
4 Replies

5. Shell Programming and Scripting

Date comparision in Unix

Hi All, I would need your help to compare dates in my script. Say if I have the dates in a file I need to comapre these dates with yesterday's date and the dates which are older than yesterday needs to be displayed. Example: 03/22/2012 03/24/2012 03/20/2012 03/21/2012 03/12/2012... (1 Reply)
Discussion started by: pdreddy34
1 Replies

6. UNIX for Advanced & Expert Users

Comparision of two files.

File Structure file1.txt.arch 029429288,1,,,02087400376,N,02087400376,N,0,02087400376,N,0,0,8010,08000151736,U,N,,08000151736,U,20100726111237,20100726111237,0,20100726111651,00004140,16,16,10,N;... (1 Reply)
Discussion started by: ravigupta2u
1 Replies

7. Shell Programming and Scripting

Column comparision in two files

Hi, I need to compare a column in two different csv files file1 xyz.com,2/2/12,a,b,c eg.com,2/2/23,a,b,ga file2 1,2,ua,xyz.com 1,2,ua,abc.com 1,2,ua,eg.com 1,2,ua,easg.com 1,2,ua,zth.com Read all entries in file1(which has 1000+) and compare column1 of file1 with the column4... (13 Replies)
Discussion started by: nuthalapati
13 Replies

8. Shell Programming and Scripting

comparision of string in various files

i want to take position 19-24(only first line) from all files and need to compare any duplication is there or not. If duplication, then i have to print the file names. I have written to take the characters from 19-24 from all files. but how to compare ? ... (1 Reply)
Discussion started by: senthil_is
1 Replies

9. Shell Programming and Scripting

Unix File Comparision

I have a file named file1 which contains numbers in sequence like... 1 2 3 7 8 Then i have file File 2 that contains 4 5 ........so i need to compare both files so that i can find out the missing entry in the sequence is 6.......These files are flat files which contain and so i need to... (5 Replies)
Discussion started by: coolguy01
5 Replies

10. Shell Programming and Scripting

How to perform comparision in unix

I am trying to perform a simple if/else check. if ; then mkdir /wdnet/oracletest else mkdir $CON_DIR fi I guess I don't understand the unix basics about comparisons. My scripts always executes the if, even though my CON_DIR variable is not blank. What am I doing... (5 Replies)
Discussion started by: artfuldodger
5 Replies
Login or Register to Ask a Question