News for hackers. Stuff that matters.
Re:Remove first 300M lines from 700 GB file on 1TB disk by seppel on Tuesday September 22, 2020 @10:28AM (#24554729)
There's nothing inherently wrong with reading and writing to the same file (as least if it is a binary file). And if you read at offset x and write at offset x-y you can easily move contents around with only a very small buffer. Just be sure that you move in the correct direction, so that you dont override stuff you need later.

That people normally use temporary files, has two reasons: The first is that it is much safer if something goes wrong. You then still have the original and not some half-way processed file. The other reason is that reading and writing in text mode does not really work. But you can of course process text files as binary files and deal with line endings yourself.

There are no comments on this comment yet.