First note: adding in the middle of a file is impossible (overwritting is possible).
Second note: In my post above I did not use $. (I did think about it though), because the OP speaks about widgets, so I guess that a widget is a special kind of line, but I can be wrong ofc...
Seek and tell in this case would be hard to use.
It would be possible to use it when the following steps are followed:
- A new temp file is created,
- The original file is opened for reading,
- File is read line by line
- If line matches the Database-string:
- Print to temp-file
- Print a fixed amount of (empty) bytes to the file, store the starting address of this data in a var (by using tell)
- Go to the previous point where empty-bytes where added (with seek) and overwrite them with the correct data.
- Jump back to the place where we were. (using seek)
- If it didn't match, check for widget etc and print to temp file.
Some remarks by this story: how much bytes should be reserved for the string?
- preferably it would be exactly the number of bytes that are needed. This could be accomplished by storing the number as an integer instead of ASCII for example,
- If too few bytes are added then vital information is overwritten,
- If too much bytes are added then the file is filled with empty data.
Using seek and tell would be possible if and only if a fixed number of bytes are added, so you can open a new (temp), write data to it while you read, add some empty bytes (which will be overriden at a later point) and do the ma
| [reply] [d/l] |