I have a somewhat unusual problem. Because of my predecessor's design, I have a 27 MB file and I need to find a specific byte in it, like say the 100,000th byte. I then have to delete everything between then 100,000th and 150,000th byte.
The file is broken up into a header file (which ends with
[END] after about 10,000 characters) and the actual data, which is all in byte form. The 27 million bytes are separated over about 15000 lines.
Any help would be greatly appreciated.
One solution in your case (unless you have strict restriction on space usage) would be to copy your file into another skipping bytes that you do not need. Depends on how you count nth byte you may need to open files in binary mode. You may rename source file to temp open new file with original name, do actual copy and delete source. Or you can copy content to temp file, then delete original and rename temp into original name. If you have restriction on disk space you can store file remaining (from 150,000th to the end in your example) truncate original file to 100,000th and then copy that remaining back.