How do you remove the last line of a file?

Minh Tung

New member
How do you remove the last line of a file?
Answer
You can remove the newline character at the end of file using following easy way:
  1. head -c -1 file. From man head : -c, –bytes=[-]K print the first K bytes of each file; with the leading ‘-‘, print all but the last K bytes of each file.
  2. truncate -s -1 file.
 

Tìm kiếm

Back
Top