If your source files are contstant size you can do this reasonably. Otherwise you have a problem as a file is just sequential bits.
# source files
aaa
bbbb
cc
ddd
# concat file
aaabbbbccddd
# replace constant size 2nd file with xxxx
aaaxxxxccddd
# but if we replace it with a shorter or longer file
aaaxxxbccddd #whoops
aaaxxxxxcddd #oh dear
You may be able to do some optimisation by not re-writing the part of the file before the changes, if you have freedom over the order the data is in perhaps you can move the most frequently changed files to the end of the stream so you are often not re-writing most of the file.
If you also own the reader script you have more options open, a couple spring to mind:
- Replace file with linked list
- allow null values in the file
- Read direct from the source files
Cheers, R. |