Solved

Need sed script to remove last line from file.

Posted on 2006-10-22
5
1,023 Views
Last Modified: 2013-12-16
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
0
Comment
Question by:tr5
  • 3
  • 2
5 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 500 total points
Comment Utility
Hi tr5,

head -n -1 infile > tempfile
mv tempfile infile

Cheers!
sunnycoder
0
 
LVL 45

Expert Comment

by:sunnycoder
Comment Utility
sed equivalent will be

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

Author Comment

by:tr5
Comment Utility
Which is quicker / more efficient? I need to do it often.
0
 
LVL 45

Expert Comment

by:sunnycoder
Comment Utility
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
 

Author Comment

by:tr5
Comment Utility
Thanks
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Suggested Solutions

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now