Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
How to print all file except last 10 lines?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
mhodak
Veteran
Veteran


Joined: 15 Nov 2003
Posts: 1218

PostPosted: Wed Mar 17, 2004 6:58 am    Post subject: How to print all file except last 10 lines? Reply with quote

I want to print content of a file on a screen with the exception of last 10 lines.
I am probably missing something simple, but I cannot find head or tail options that can do this.

Anybody knows?
Back to top
View user's profile Send private message
think4urs11
Bodhisattva
Bodhisattva


Joined: 25 Jun 2003
Posts: 6659
Location: above the cloud

PostPosted: Wed Mar 17, 2004 7:26 am    Post subject: Reply with quote

Code:
man head
would have given you this:

Code:
head --lines=-10 filename


HTH
T.
_________________
Nothing is secure / Security is always a trade-off with usability / Do not assume anything / Trust no-one, nothing / Paranoia is your friend / Think for yourself
Back to top
View user's profile Send private message
mhodak
Veteran
Veteran


Joined: 15 Nov 2003
Posts: 1218

PostPosted: Wed Mar 17, 2004 7:47 am    Post subject: Reply with quote

That indeed works, but I actually need to do it on RedHat server which uses slightly older version of head (4.5.3), which does accept negative numbers as arguments in "lines=" and so this does not work.
My gentoo uses version 5.0.91.

What can I use if "head --lines=-10" does not work ?
Back to top
View user's profile Send private message
nevynxxx
Veteran
Veteran


Joined: 12 Nov 2003
Posts: 1123
Location: Manchester - UK

PostPosted: Wed Mar 17, 2004 8:30 am    Post subject: Reply with quote

I'm sure it wouldn't be too difficult to write a script that copies the file to a tmp file, sed's it to remove the last 10 lines, then cat's it. Or copy the file to your gentoo box and use head there!
*edit*
Code:

cp $1 /tmp/$1
sed -e :a -e '$d;N;2,10ba' -e 'P;D' /tmp/$1 | cat


should work, the sed line is taken from "Handy sed 1 liners".
_________________
My Public Key

Wanted: Instructor in the art of Bowyery
Back to top
View user's profile Send private message
spb
Retired Dev
Retired Dev


Joined: 02 Jan 2004
Posts: 2135
Location: Cambridge, UK

PostPosted: Wed Mar 17, 2004 5:58 pm    Post subject: Reply with quote

Code:
head -n $(($(wc -l <filename) - 10)) filename

Gets the line count of filename, subtracts 10, and passes that to head.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum