Need sed script to remove last line from file.

tr5
tr5 used Ask the Experts™
on
Hi

I need a sed script (or other) to remove the last line from a file and to resave to the same file.

Thanks
tr5
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2006
Commented:
Hi tr5,

head -n -1 infile > tempfile
mv tempfile infile

Cheers!
sunnycoder
Top Expert 2006

Commented:
sed equivalent will be

 sed '$d' infile > tempfile
 mv tempfile infile
tr5

Author

Commented:
Which is quicker / more efficient? I need to do it often.
Top Expert 2006

Commented:
Both should have comparable performance since both scan input for lines. Head might be slightly more efficient since this is the job it is built for - displaying specific lines.
tr5

Author

Commented:
Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial