Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Need sed script to remove last line from file.

Posted on 2006-10-22
5
Medium Priority
?
1,045 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 2000 total points
ID: 17783482
Hi tr5,

head -n -1 infile > tempfile
mv tempfile infile

Cheers!
sunnycoder
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 17783487
sed equivalent will be

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

Author Comment

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

Expert Comment

by:sunnycoder
ID: 17783580
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
ID: 17784219
Thanks
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month11 days, 12 hours left to enroll

916 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