A simpler solution than the accepted one:
truncate -s -1 <<file>>
From the truncate
man page (man truncate
):
-s, --size=SIZE
set or adjust the file size by SIZE
SIZE may also be prefixed by one of the following modifying characters:
'+' extend by, '-' reduce by, '<' at most, '>' at least, "https://stackoverflow.com/" round down
to multiple of, '%' round up to multiple of.