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

Posted by macek on Stack Overflow See other posts from Stack Overflow or by macek
Published on 2010-04-23T20:19:26Z Indexed on 2010/04/23 20:23 UTC
Read the original article Hit count: 336

Filed under:
|
|
|

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

© Stack Overflow or respective owner

Related posts about ruby

Related posts about parse