|
|
Remove last lines
Hi,
How to remove the last 10 lines from stdin ?
Thanks
|
|
0
|
|
|
|
Reply
|
bob123 (66)
|
12/21/2009 8:51:05 PM |
|
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'
|
|
0
|
|
|
|
Reply
|
pk
|
12/21/2009 8:59:33 PM
|
|
On December 21, 2009 15:51, in comp.unix.shell, bob123@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. ------
|
|
0
|
|
|
|
Reply
|
Lew
|
12/21/2009 9:25:27 PM
|
|
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
|
|
0
|
|
|
|
Reply
|
Stephane
|
12/22/2009 7:35:28 AM
|
|
Lew Pitcher wrote:
> On December 21, 2009 15:51, in comp.unix.shell, bob123@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
|
|
0
|
|
|
|
Reply
|
Janis
|
12/22/2009 8:39:24 AM
|
|
On Dec 22, 4:51=A0am, "bob123" <bob...@gmail.com> wrote:
> Hi,
>
> How to remove the last 10 lines from stdin ?
>
> Thanks
head -n $(( $(wc -l <file) - 10 )) file
|
|
0
|
|
|
|
Reply
|
mik3
|
12/22/2009 10:14:52 AM
|
|
> head -n $(( $(wc -l <file) - 10 )) file
nice...
|
|
0
|
|
|
|
Reply
|
bob123
|
12/22/2009 10:53:40 AM
|
|
|
6 Replies
2045 Views
(page loaded in 0.077 seconds)
|
|
|
|
|
|
|
|
|