I want to delete certain lines in a file and insert certain lines in the same file based on whether certain parts of the line match a specified string. Is there a way of doi
You can't easily "cut" a section of a file out in-place. You always make a temporary copy somewhere. This isn't a C thing; it's true for any language.
You could mmap the file, and then when you find the line you want to erase, you can memcpy everything after it to the location of the start of the line. I'd question how efficient that would be; the temporary file might be quicker.