Entry tags:
dear lazyweb
I want to run a command that will give me the contents of a file, except for the last two lines. I know that tail -2 filename will give me the last two lines of a file, and head -2 filename will give me the first two lines of a file. Now, tail +2 filename will give me contents of a file, starting with line 2. It's not a symmetrical option, but i can at least work with that. However, the head command lacks this elegant mode; otherwise, i would infer that head +3 filename would give me what i want. Is there a simple command that can do what i want? I figure i can implement this in some fugly perl script, but that is not the damn point.

assuming you're using bash.
Re: assuming you're using bash.
Re: assuming you're using bash.
But that makes two passes through the file and forks an unnecessary cut!
Here, still in two passes, but golfed a bit:
And what the hell, here's the fugly perl anyway. One pass, but Perl:
Re: assuming you're using bash.
Only Fuggly Whiners about solution spaces...
no subject
(edit) in this case, head --lines=-2
(edit 2) output of head --version:
head (GNU coreutils) 6.10
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by David MacKenzie and Jim Meyering.
no subject
no subject
YAAAAAAAAAAY
GNU
Anytime you can run code written by DJM I say uoi are the winner..
no subject
Heh, I just thought of an evil one.
no subject
no subject
no subject
no subject
fucking awesome!
this is my new favorite unix command.
(replacing "yes")
no subject
after a few rounds of optimization
no subject
no subject
no subject
decaf...
no subject
nasty but it works and is simple to understand.
sed -e 'N;$!P;$!D;$d'
actually does want you want (but has a bug if the file is only 1 line long).
(I googled that... took 5 seconds "sed all but last 2 lines". Don't think I could have created it on my own since I'm not too good with sed pattern buffer mangling)
no subject
I was gonna say, "Count the lines, and then get count -2." I had no idea the poetry.