直接访问和更新硬盘上的文件部分

时间:2021-10-17 00:00:21

I wonder if I can do the following and how: I have an extremely large file in a fixed width format stored in a hard disk with *NIX system. I want to know if one can do update on a portion of the big file without read in and write out the entire file in the memory. For example of the following file, I want to go to a specific location "5" on the hard disk and replace only the content EE to ZZ without rewrite the entire file.

我想知道我是否可以执行以下操作以及如何:我有一个固定宽度格式的非常大的文件存储在带有* NIX系统的硬盘中。我想知道是否可以在没有读入的情况下对大文件的一部分进行更新,并将整个文件写出内存。例如,对于以下文件,我想转到硬盘上的特定位置“5”并仅将内容EE替换为ZZ而不重写整个文件。

1 AA 2 BB 3 CC 4 DD 5 EE ->ZZ 6 FF 7 GG 8 HH 9 II .. ..

1 AA 2 BB 3 CC 4 DD 5 EE - > ZZ 6 FF 7 GG 8 HH 9 II .. ..

Regardless of programming language, is this possible?

无论编程语言如何,这可能吗?

1 个解决方案

#1


That's easy to do, as long as you replace contents with new contents - you can't add or remove anything. Think of the file contents as a long strip of tape stuck to a table. You can cut out a piece of tape and replace it with another piece of the exact same length without disturbing the rest of the tape. But if you want to replace the piece you cut out with a shorter or longer piece, you have to pull up lots of tape and stick it back down somewhere else to keep a continuous strip of tape.

只要您用新内容替换内容,这很容易做到 - 您无法添加或删除任何内容。将文件内容想象成粘在桌子上的长条带。您可以剪下一块胶带,然后用另一块完全相同的长度替换它,而不会打扰其余的胶带。但是如果你想用更短或更长的一块来替换你切出的那块,你必须拉起大量的胶带并将其粘在其他地方,以保持连续的胶带。

#1


That's easy to do, as long as you replace contents with new contents - you can't add or remove anything. Think of the file contents as a long strip of tape stuck to a table. You can cut out a piece of tape and replace it with another piece of the exact same length without disturbing the rest of the tape. But if you want to replace the piece you cut out with a shorter or longer piece, you have to pull up lots of tape and stick it back down somewhere else to keep a continuous strip of tape.

只要您用新内容替换内容,这很容易做到 - 您无法添加或删除任何内容。将文件内容想象成粘在桌子上的长条带。您可以剪下一块胶带,然后用另一块完全相同的长度替换它,而不会打扰其余的胶带。但是如果你想用更短或更长的一块来替换你切出的那块,你必须拉起大量的胶带并将其粘在其他地方,以保持连续的胶带。