Q:

Ruby File IO question; Maintain file read position between script executions

I have two files a.txt and b.txt (henceforth a and b).
My script iterates through a, does some operation, and potentially inserts a line to b.
In the event the script stops, I need it to pick up where it left off. In the example below:

foo was copied to b
bar was copied to b
zim was not copied to b (did not pass some criteria)
gaz was copied to b
Script stops (for whatever reason)

When script starts again, how to open a and start on line "dib"?
a.txt
foo
bar
zim
gaz      // <= last successful copy
dib      // <= I want to start here on next script execution
gir

b.txt
foo
bar
gaz      // <= note omission of "zim" above gaz

Note:
a.txt is almost 1,000,000 lines

A:

Hey Macek - you could use seek to find the line in the original file.  Check out IO#seek http://ruby-doc.org/core/classes/IO.html#M002280

