From: bob123 on
Hi,

How to remove the last 10 lines from stdin ?

Thanks


From: pk on
bob123 wrote:

> How to remove the last 10 lines from stdin ?

For example:

awk 'NR>10{print a[NR%10]}{a[NR%10]=$0}'

you can adapt it to work for a variable number of lines by doing this:

awk -v n=10 'NR>n{print a[NR%n]}{a[NR%n]=$0}'

Using sed:

sed -n ':a;1,10!{P;N;D;};N;ba'
From: Lew Pitcher on
On December 21, 2009 15:51, in comp.unix.shell, bob123(a)gmail.com wrote:

> Hi,
>
> How to remove the last 10 lines from stdin ?

head --lines=-10 -


--
Lew Pitcher
Master Codewright & JOAT-in-training | Registered Linux User #112576
Me: http://pitcher.digitalfreehold.ca/ | Just Linux: http://justlinux.ca/
---------- Slackware - Because I know what I'm doing. ------


From: Stephane CHAZELAS on
2009-12-21, 20:59(+00), pk:
[...]
> Using sed:
>
> sed -n ':a;1,10!{P;N;D;};N;ba'


sed -ne :a -e '1,10!{P;N;D;}' -e 'N;ba'

Bearing in mind that some sed implementations have a limited
pattern space size (though POSIX requires it to be at least 8
kB)

--
St�phane
From: Janis Papanagnou on
Lew Pitcher wrote:
> On December 21, 2009 15:51, in comp.unix.shell, bob123(a)gmail.com wrote:
>
>> Hi,
>>
>> How to remove the last 10 lines from stdin ?
>
> head --lines=-10 -
>
>

$ head --lines=-10 -
head: -10: invalid number of lines

Non-standard, I assume. And not available in older GNU head versions.

Janis