in reply to Deleting all the data after a specific position in a text file.

Better in what respect? What is the format of the data? How do you find the position? Where in the data is the position located (close to the beginning or end...)?
  • Comment on Re: Deleting all the data after a specific position in a text file.

Replies are listed 'Best First'.
Re^2: Deleting all the data after a specific position in a text file.
by pankaj_it09 (Scribe) on Nov 18, 2011 at 13:09 UTC
    The file pointer is present at the EOF and I want to remove the last 100 characters.

      See the documentation for seek, specifically the WHENCE parameter.

      Update: I am assuming that you mean the last 100 bytes, not characters.

      Update 2: Specifically, seek to position 100 from the end, and tell what the current position is, then truncate to that length. ISTR (but cannot recall at the moment) a syscall to "truncate from this point to the end of the file". Oops, just use the FH version of truncate. See also Re^3: Deleting all the data after a specific position in a text file..

      --MidLifeXis