I have two files that are several hundred MB in size. These files each contain a sorted key. What I would like to do is read each line from each file one at a time. If a match is found, write it out to a “matched” file otherwise write to one of two “nonmatch” files. The main issue that I need to avoid is reading the files into memory. I think I understand how I want to test the condition, what I don't understand is how the looping will work.
input files
file0 file1
1 2
2 4
3 5
5 8
7 9
9
logical test
1<=>2 -1 next 0, keep 1, print to nomatch0
2<=>2 0 next 0, next 1, print to match
3<=>4 -1 next 0, keep 1, print to nomatch0
5<=>4 1 keep 0, next 1, print to nomatch1
5<=>5 0 next 0, next 1, print to match
7<=>8 -1 next 0, keep 1, print to nomatch0
9<=>8 1 keep 0, next 1, print to nomatch1
9<=>9 0 next 0, next 1, print to match
output files
matched nomatch0 nomatch1
2 1 4
5 3 8
9 7
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.