Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

shell: delete the last line of a huge text log file [duplicate]

Tags:

shell

tail

I asked a question regarding popping the last line of a text file in PHP, and now, is it possible to re-write the logic in shell script?

I tried this to obtain the last line:

tail -n 1 my_log_file.log

but I am not sure how can I remove the last line and save the file.

P.S. given that I use Ubuntu server.

like image 940
Raptor Avatar asked Aug 29 '12 11:08

Raptor


1 Answers

To get the file content without the last line, you can use

head -n-1 logfile.log

(I am not sure this is supported everywhere)

or

sed '$d' logfile.log
like image 192
choroba Avatar answered Sep 20 '22 13:09

choroba