views:

30

answers:

1

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:

  1. foo was copied to b
  2. bar was copied to b
  3. zim was not copied to b (did not pass some criteria)
  4. gaz was copied to b
  5. 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

+3  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

Arcterex