last=$(tail -n 1 file)<br>first=$(head -n 1 file)<br>sed -i -e &quot;/$last/d&quot; -e &quot;/$first/ i\<br>$last<br>&quot; file<br><br><div class="gmail_quote">On Wed, Mar 28, 2012 at 11:27 AM, <a href="mailto:mike@trausch.us">mike@trausch.us</a> <span dir="ltr">&lt;<a href="mailto:mike@trausch.us">mike@trausch.us</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On 03/28/2012 11:10 AM, Lightner, Jeff wrote:<br>
&gt; What is the best way to move that last line of a text file to be the<br>
&gt; first line?<br>
<br>
</div>&quot;Best&quot; is subjective...<br>
<div class="im"><br>
&gt; Please answer the question as asked and don’t suggest making the file be<br>
&gt; in the correct order when we receive it or changing the automated<br>
&gt; processing to read the last line first.  Assume those aren’t options.<br>
<br>
</div>k...<br>
<div class="im"><br>
&gt; What I came up with was to do tail -1 &gt;newfile and head -&lt;number of<br>
&gt; lines – 1&gt; but was thinking there ought to be a better way.<br>
<br>
</div>I would do something similar:<br>
<br>
#!/bin/bash<br>
# Put the last line of the file specified into the<br>
# first line of the file specified.<br>
<br>
TMP_FILE=&quot;$1&quot;.$$<br>
tac &quot;$1&quot;|head -n 1 &gt; &quot;${TMP_FILE}&quot;<br>
tac &quot;$1&quot;|tail -n +2|tac &gt;&gt; &quot;${TMP_FILE}&quot;<br>
mv &quot;${TMP_FILE}&quot; &quot;$1&quot;<br>
<span class="HOEnZb"><font color="#888888"><br>
        --- Mike<br>
<br>
--<br>
A man who reasons deliberately, manages it better after studying Logic<br>
than he could before, if he is sincere about it and has common sense.<br>
                                   --- Carveth Read, “Logic”<br>
<br>
</font></span><br>_______________________________________________<br>
Ale mailing list<br>
<a href="mailto:Ale@ale.org">Ale@ale.org</a><br>
<a href="http://mail.ale.org/mailman/listinfo/ale" target="_blank">http://mail.ale.org/mailman/listinfo/ale</a><br>
See JOBS, ANNOUNCE and SCHOOLS lists at<br>
<a href="http://mail.ale.org/mailman/listinfo" target="_blank">http://mail.ale.org/mailman/listinfo</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>-- <br>James P. Kinney III<br><br>As long as the general population is passive, apathetic, diverted to 
consumerism or hatred of the vulnerable, then the powerful can do as 
they please, and those who survive will be left to contemplate the 
outcome.<br>- <i><i><i><i>2011 Noam Chomsky<br><br><a href="http://heretothereideas.blogspot.com/" target="_blank">http://heretothereideas.blogspot.com/</a><br></i></i></i></i><br>