Need sed script to remove last line from file.

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
tr5Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
sunnycoderConnect With a Mentor Commented:
Hi tr5,

head -n -1 infile > tempfile
mv tempfile infile

Cheers!
sunnycoder
0
 
sunnycoderCommented:
sed equivalent will be

 sed '$d' infile > tempfile
 mv tempfile infile
0
 
tr5Author Commented:
Which is quicker / more efficient? I need to do it often.
0
 
sunnycoderCommented:
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.
0
 
tr5Author Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.