Solved

Need sed script to remove last line from file.

Posted on 2006-10-22
5
1,030 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 500 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Linux boot cd to do hardware report on PC? 3 76
maybe no no httpd.conf 6 77
Run Secure WMI query from CentOS 5 132
Krita v3 Linux Mint/Ubuntu 16.04 9 12
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…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
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.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

740 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