Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Compare two large files and extract a matching row...

by mzedeler (Pilgrim)
on Apr 17, 2012 at 11:37 UTC ( [id://965495]=note: print w/replies, xml ) Need Help??


in reply to Compare two large files and extract a matching row...

Here is an approach that should work:

1. Read file 1, pulling field 2 out and storing it in a hash for fast lookup.

while(<FILE1>) { my @fields = split /|/; $lookup{$fields[1]} = 1; }

2. Read file 2 line by line and put the line in your output file if field 5 is in the %lookup hash.

By using this approach, you will never need to have more than one line from each file in memory at any time, and the ids from file 2. This should be both fast and memory efficient.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://965495]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-20 01:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found