<div dir="ltr">man head<div><br></div><div>head --lines=-5 textfile.txt</div><div><br></div><div>all but the last 5 lines.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 4, 2015 at 3:49 PM, Robert Keizer <span dir="ltr"><<a href="mailto:robert@keizer.ca" target="_blank">robert@keizer.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Idea from thread below:<br>
<br>
| awk '{if(a) print a;a=b;b=$0}'<br>
<br>
Note that you might want to include a little more logic if you want<br>
blanklines in there.. This doesn't store all of it in a file or in ram.<br>
<br>
<br>
<a href="http://askubuntu.com/questions/475694/awk-command-to-print-all-the-lines-except-the-last-three-lines" target="_blank">http://askubuntu.com/questions/475694/awk-command-to-print-all-the-lines-except-the-last-three-lines</a><br>
<span class=""><br>
On 2015-03-04 3:33 PM, Adam Thompson wrote:<br>
> Like Tim said, you first have to know how many lines exist in the file<br>
> before you can do anything other than stream processing.<br>
> On moderately-sized inputs, "wc -l" works reasonably well. On large<br>
> inputs, there's no way to do this efficiently unless you're willing to<br>
> sacrifice accuracy.<br>
><br>
> F=filename<br>
> L=$(wc -l $F)<br>
> head -n $(( $L - num_of_ignored_lines ))<br>
><br>
> -Adam<br>
><br>
> On March 4, 2015 2:36:24 PM CST, Kevin McGregor<br>
> <<a href="mailto:kevin.a.mcgregor@gmail.com">kevin.a.mcgregor@gmail.com</a>> wrote:<br>
><br>
> Can someone help me out? I'm too tired to think straight.<br>
><br>
> Is there an easy/short way to get all BUT the last n lines of a<br>
> text file/input? All I can think of is reversing the input line<br>
> order and tail +n or something like that. FYI the input is not<br>
> very big.<br>
><br>
> Kevin<br>
><br>
</span>> ------------------------------------------------------------------------<br>
<span class="">><br>
> Roundtable mailing list<br>
> <a href="mailto:Roundtable@muug.mb.ca">Roundtable@muug.mb.ca</a><br>
> <a href="http://www.muug.mb.ca/mailman/listinfo/roundtable" target="_blank">http://www.muug.mb.ca/mailman/listinfo/roundtable</a><br>
><br>
><br>
> --<br>
> Sent from my Android device with K-9 Mail. Please excuse my brevity.<br>
><br>
><br>
</span>> _______________________________________________<br>
<div class="HOEnZb"><div class="h5">> Roundtable mailing list<br>
> <a href="mailto:Roundtable@muug.mb.ca">Roundtable@muug.mb.ca</a><br>
> <a href="http://www.muug.mb.ca/mailman/listinfo/roundtable" target="_blank">http://www.muug.mb.ca/mailman/listinfo/roundtable</a><br>
<br>
<br>
</div></div><br>_______________________________________________<br>
Roundtable mailing list<br>
<a href="mailto:Roundtable@muug.mb.ca">Roundtable@muug.mb.ca</a><br>
<a href="http://www.muug.mb.ca/mailman/listinfo/roundtable" target="_blank">http://www.muug.mb.ca/mailman/listinfo/roundtable</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">John Lange<br><a href="http://www.johnlange.ca">www.johnlange.ca</a></div>
</div>