Delete last line from the file

in sed $ is the last line so to delete the last line:

sed '$d' <file>

$ for the last line:

sed '$d' file

cat file.txt | head -n -1 > new_file.txt

Beware, it seems, depending on the last line of file.txt (if it ends with EOF, or \n and then EOF), the number of lines in new_file.txt may be the same (as file.txt) after this command (this happens when there is no \n) - in any case, the contents of the last line is deleted.

Also, note that you must use a second (intermediate) file. If you cat and redirect to the same file, you'll erase it.