From: bob123 on 21 Dec 2009 15:51 Hi, How to remove the last 10 lines from stdin ? Thanks
From: pk on 21 Dec 2009 15:59 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 21 Dec 2009 16:25 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 22 Dec 2009 02:35 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 22 Dec 2009 03:39
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 |