Remove first 300M lines from 700 GB file on 1TB disk
My first idea was to solve this "queue" (FIFO) problem with a "two stacks" solution: Without special system calls, files can only be appended and truncated at the end, not the beginning, so they behave like a stack. Two stacks can be used to simulate a queue.Implementation sketch:1) Successively read the last 1 kiB from the source file, append it to a temporary file, and truncate 1 kiB from the source file.2) Truncate the last 300M lines from the temporary file.3) Successively read the last 1 kiB from the temporary file, append it to the destination file, and truncate 1 kiB from the temporary file.This way, you never need more than 1 kiB of additional disk space (tune this number as desired). I think this is an elegant solution. The correct solution, of course, is to buy a second disk.