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

The file pointer is present at the EOF and I want to remove the last 100 characters.
  • Comment on Re^2: Deleting all the data after a specific position in a text file.

Replies are listed 'Best First'.
Re^3: Deleting all the data after a specific position in a text file.
by MidLifeXis (Monsignor) on Nov 18, 2011 at 13:25 UTC

    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