View previous topic :: View next topic |
Author |
Message |
mhodak Veteran
Joined: 15 Nov 2003 Posts: 1218
|
Posted: Wed Mar 17, 2004 6:58 am Post subject: How to print all file except last 10 lines? |
|
|
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 |
|
|
think4urs11 Bodhisattva
Joined: 25 Jun 2003 Posts: 6659 Location: above the cloud
|
Posted: Wed Mar 17, 2004 7:26 am Post subject: |
|
|
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 |
|
|
mhodak Veteran
Joined: 15 Nov 2003 Posts: 1218
|
Posted: Wed Mar 17, 2004 7:47 am Post subject: |
|
|
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 |
|
|
nevynxxx Veteran
Joined: 12 Nov 2003 Posts: 1123 Location: Manchester - UK
|
Posted: Wed Mar 17, 2004 8:30 am Post subject: |
|
|
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 |
|
|
spb Retired Dev
Joined: 02 Jan 2004 Posts: 2135 Location: Cambridge, UK
|
Posted: Wed Mar 17, 2004 5:58 pm Post subject: |
|
|
Code: | head -n $(($(wc -l <filename) - 10)) filename |
Gets the line count of filename, subtracts 10, and passes that to head. |
|
Back to top |
|
|
|