Here is a solution written in C for Windows. It will execute and complete on 700,000 lines a 245 MB file in the shortest possible time. (0.14 s)
Basically, I store a memory card so that I can access the content using the functions used to access raw memory. Once the file has been matched, I simply use the strchr function to find the location of one of the pair of characters used to indicate EOL in the windows (\ n and \ r) - this tells us how long the bytes in the first line are.
From here I just memcpy from the first byte f of the second line to the beginning of the memory mapping area (basically, the first byte in the file).
Once this is done, the file will not be displayed, the file descriptor mem-mapped will be closed, and then we will use the SetEndOfFile function to reduce the length of the file along the length of the first line. When we close the file, it decreased by this length, and the first line disappeared.
Having the file already in memory, as I just created and wrote, it obviously changes the execution time a little, but the window caching mechanism is the βculpritβ here - the very mechanism that we use to execute the operations is very fast.
The test data is the source of the program duplicated 100,000 times and saved as testInput2.txt (paste it 10 times, select everything, copy, paste 10 times - replace the original 10, a total of 100 times - repeat until the output was large enough. I stayed here because more seemed to make Notepad ++ βbitβ unhappy)
Error checking in this program practically does not exist, and it is expected that the input will not be UNICODE, i.e. input 1 byte per character. The EOL sequence is 0x0D, 0x0A (\ r, \ n)
Code:
#include <stdio.h> #include <windows.h> void testFunc(const char inputFilename[] ) { int lineLength; HANDLE fileHandle = CreateFile( inputFilename, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH, NULL ); if (fileHandle != INVALID_HANDLE_VALUE) { printf("File opened okay\n"); DWORD fileSizeHi, fileSizeLo = GetFileSize(fileHandle, &fileSizeHi); HANDLE memMappedHandle = CreateFileMapping( fileHandle, NULL, PAGE_READWRITE | SEC_COMMIT, 0, 0, NULL ); if (memMappedHandle) { printf("File mapping success\n"); LPVOID memPtr = MapViewOfFile( memMappedHandle, FILE_MAP_ALL_ACCESS, 0, 0, 0 ); if (memPtr != NULL) { printf("view of file successfully created"); printf("File size is: 0x%04X%04X\n", fileSizeHi, fileSizeLo); LPVOID eolPos = strchr((char*)memPtr, '\r'); // windows EOL sequence is \r\n lineLength = (char*)eolPos-(char*)memPtr; printf("Length of first line is: %ld\n", lineLength); memcpy(memPtr, eolPos+2, fileSizeLo-lineLength); UnmapViewOfFile(memPtr); } CloseHandle(memMappedHandle); } SetFilePointer(fileHandle, -(lineLength+2), 0, FILE_END); SetEndOfFile(fileHandle); CloseHandle(fileHandle); } } int main() { const char inputFilename[] = "testInput2.txt"; testFunc(inputFilename); return 0; }