In Linux, I have a rather large file with some extraneous information tacked on to the end of it. Let’s say for example I know there are 314 bytes of extraneous data at the end of a 1.6GB file.
Of course it is very easy and efficient to add more data to the end of a file, but what can I do to remove it without having to copy the first portion of that file into another (or overwrite said file)?
Edit
I’m seeing some good advice on doing this in C. I was hoping to script it from the commandline, but failing that I would be more inclined to doing it in python than C.
I see that python has a truncate method on its file object but it seems to be demolishing my file no matter how i use it–I should be able to figure this one out, but of course answers are more than welcome still.
use the function
truncatehttp://linux.die.net/man/2/truncate
truncate takes the file name
ftruncate takes an open file descriptor
both of these set the file length to
lengthso it either truncates or elongates (in the latter case, the rest of the file will be filled with NULL/ZERO)[edit]
truncate (linux shell command) will work also
[/edit]