stripping the last line

stripping the last line

Post by Simon Galt » Fri, 07 Oct 1994 04:48:09



Hello all.  This is probably a FAQ, but I just read through the
seven-part FAQ recently posted, and couldn't find the answer, so here goes:

I have a file of statistics, and the last line is not significant and I
wish to discard it, as more data will be appended to the file daily and I
want a certain purity of data. :)

Is there a *simple* way of stripping the last line off a file, or,
failing this, is there a *not so simple* way?

Your help will be most appreciated.
                                        Simon Galton
--
||| | || || Generic Sig                                         ''`
||| | || || ===========                                         O-O
||| | || ||                                                      L

|| 01416 || Information Technology Dept, Sheridan College, Oakville, ON, Canada

 
 
 

stripping the last line

Post by David W. Tamk » Fri, 07 Oct 1994 13:21:35




| I have a file of statistics, and the last line is not significant and I
| wish to discard it, as more data will be appended to the file daily and I
| want a certain purity of data. :)
|
| Is there a *simple* way of stripping the last line off a file, or,
| failing this, is there a *not so simple* way?

sed '$ d' inputfile > outputfile

or, to do it without renaming,

ed - file << \end_ed
$d
w
q
ended

 
 
 

stripping the last line

Post by Andrew Dunst » Sun, 09 Oct 1994 06:22:07


sed '$d' filename > /tmp/filename; mv /tmp/filename filename

or you could write a C program to truncate the file in situ, but
this seems like overkill. (an ed script might also do this for you).

cheers

andrew