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
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
© Stack Overflow or respective owner