Repositioning file pointer to add header to file

Hello all,

i have a file that gets written during the course of the simulation (think of it as a log file). once the sim ends , i would like to add a header to it.
i tried $rewind to reposition the file pointer to the top of the file. however, the header still got added to the EOF only.

Any help would be great , thank you!

In reply to abisha:

When a file is opened for append (that is, when type is “a” or “a+”), it is impossible to overwrite information already in the file. $fseek can be used to reposition the file pointer to any position in the file, but when output is written to the file, the current file pointer is disregarded. All output is written at the end of the file and causes the file pointer to be repositioned at the end of the output.

But even if you fix this, you cannot prepend a header to a file; it would overwrite existing data. You might what to concatenate the header with the existing file in a post-simulation script.