in reply to How to chomp the last new line character from the file
- Verify that the file exists and that it is writable by you.
-
Seek to the end of the file, obtaining its length in bytes. Exit if zero.
-
Seek one byte back from where you are. Read that byte. Exit if not a newline. (Assuming no double-bye character-set nonsense; otherwise, you must back up one character.)
-
Truncate the file at length - 1.