<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">&lt;<a href="mailto:robert@keizer.ca" target="_blank">robert@keizer.ca</a>&gt;</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 &#39;{if(a) print a;a=b;b=$0}&#39;<br>
<br>
Note that you might want to include a little more logic if you want<br>
blanklines in there..  This doesn&#39;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>
&gt; Like Tim said, you first have to know how many lines exist in the file<br>
&gt; before you can do anything other than stream processing.<br>
&gt; On moderately-sized inputs, &quot;wc -l&quot; works reasonably well. On large<br>
&gt; inputs, there&#39;s no way to do this efficiently unless you&#39;re willing to<br>
&gt; sacrifice accuracy.<br>
&gt;<br>
&gt; F=filename<br>
&gt; L=$(wc -l $F)<br>
&gt; head -n $(( $L - num_of_ignored_lines ))<br>
&gt;<br>
&gt; -Adam<br>
&gt;<br>
&gt; On March 4, 2015 2:36:24 PM CST, Kevin McGregor<br>
&gt; &lt;<a href="mailto:kevin.a.mcgregor@gmail.com">kevin.a.mcgregor@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt;     Can someone help me out? I&#39;m too tired to think straight.<br>
&gt;<br>
&gt;     Is there an easy/short way to get all BUT the last n lines of a<br>
&gt;     text file/input? All I can think of is reversing the input line<br>
&gt;     order and tail +n or something like that. FYI the input is not<br>
&gt;     very big.<br>
&gt;<br>
&gt;     Kevin<br>
&gt;<br>
</span>&gt;     ------------------------------------------------------------------------<br>
<span class="">&gt;<br>
&gt;     Roundtable mailing list<br>
&gt;     <a href="mailto:Roundtable@muug.mb.ca">Roundtable@muug.mb.ca</a><br>
&gt;     <a href="http://www.muug.mb.ca/mailman/listinfo/roundtable" target="_blank">http://www.muug.mb.ca/mailman/listinfo/roundtable</a><br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; Sent from my Android device with K-9 Mail. Please excuse my brevity.<br>
&gt;<br>
&gt;<br>
</span>&gt; _______________________________________________<br>
<div class="HOEnZb"><div class="h5">&gt; Roundtable mailing list<br>
&gt; <a href="mailto:Roundtable@muug.mb.ca">Roundtable@muug.mb.ca</a><br>
&gt; <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>