<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:st1="urn:schemas-microsoft-com:office:smarttags" xmlns="http://www.w3.org/TR/REC-html40" xmlns:ns0="urn:schemas-microsoft-com:office:smarttags">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 11 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]--><o:SmartTagType namespaceuri="urn:schemas-microsoft-com:office:smarttags" name="PersonName" /><!--[if !mso]>
<style>
st1\:*{behavior:url(#default#ieooui) }
</style>
<![endif]--><style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline;}
p
        {mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman";}
p.e033d674-3a3b-4ac4-8167-2659823254ee, li.e033d674-3a3b-4ac4-8167-2659823254ee, div.e033d674-3a3b-4ac4-8167-2659823254ee
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
span.EmailStyle18
        {mso-style-type:personal;
        font-family:Arial;
        color:windowtext;}
span.EmailStyle21
        {mso-style-type:personal-reply;
        font-family:Arial;
        color:navy;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
        {page:Section1;}
-->
</style><!-- Template generated by Exclaimer Mail Disclaimers on 11:10:17 Wednesday, 28 March 2012 -->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="Section1">
<p class="MsoNormal"><font size="2" color="navy" face="Arial"><span style="font-size:
10.0pt;font-family:Arial;color:navy">I found this works:<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">awk '{a[NR]=$0} END {print a[NR]; for (i=1;i&lt;NR;i&#43;&#43;) print a[i]}' originalfile &gt;newfile<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial"><o:p>&nbsp;</o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">Where you replace originalfile and newfile with real file names.<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial"><o:p>&nbsp;</o:p></span></font></p>
<p class="MsoNormal"><font size="2" color="navy" face="Arial"><span style="font-size:
10.0pt;font-family:Arial;color:navy"><o:p>&nbsp;</o:p></span></font></p>
<p class="MsoNormal"><font size="2" color="navy" face="Arial"><span style="font-size:
10.0pt;font-family:Arial;color:navy"><o:p>&nbsp;</o:p></span></font></p>
<div>
<div class="MsoNormal" align="center" style="text-align:center"><font size="3" face="Times New Roman"><span style="font-size:12.0pt">
<hr size="2" width="100%" align="center" tabindex="-1">
</span></font></div>
<p class="MsoNormal"><b><font size="2" face="Tahoma"><span style="font-size:10.0pt;
font-family:Tahoma;font-weight:bold">From:</span></font></b><font size="2" face="Tahoma"><span style="font-size:10.0pt;font-family:Tahoma"> ale-bounces@ale.org [mailto:ale-bounces@ale.org]
<b><span style="font-weight:
bold">On Behalf Of </span></b>Lightner, Jeff<br>
<b><span style="font-weight:bold">Sent:</span></b> Wednesday, March 28, 2012 11:10 AM<br>
<b><span style="font-weight:bold">To:</span></b> <st1:PersonName w:st="on">Atlanta Linux Enthusiasts</st1:PersonName><br>
<b><span style="font-weight:bold">Subject:</span></b> [ale] Move last line of a file to first line</span></font><o:p></o:p></p>
</div>
<p class="MsoNormal"><font size="3" face="Times New Roman"><span style="font-size:
12.0pt"><o:p>&nbsp;</o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">We have variable length text files being received in which the &#8220;header&#8221; line we use in automated processing is the last line of the file rather than the first
 line.<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial"><o:p>&nbsp;</o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">What is the best way to move that last line of a text file to be the first line?<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial"><o:p>&nbsp;</o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">Please answer the question as asked and don&#8217;t suggest making the file be in the correct order when we receive it or changing the automated processing to read
 the last line first.&nbsp; Assume those aren&#8217;t options.<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial"><o:p>&nbsp;</o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">What I came up with was to do tail -1 &gt;newfile and head -&lt;number of lines &#8211; 1&gt; but was thinking there ought to be a better way.<o:p></o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial"><o:p>&nbsp;</o:p></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">I see sed can deal with last line, first line and insertion but the examples I&#8217;m finding address either/or not moving last line to first line.<o:p></o:p></span></font></p>
<p class="e033d674-3a3b-4ac4-8167-2659823254ee"><font size="3" face="Times New Roman"><span style="font-size:12.0pt">&nbsp;<o:p></o:p></span></font></p>
<p class="e033d674-3a3b-4ac4-8167-2659823254ee"><font size="3" face="Times New Roman"><span style="font-size:12.0pt">&nbsp;<o:p></o:p></span></font></p>
<p class="e033d674-3a3b-4ac4-8167-2659823254ee"><font size="3" face="Times New Roman"><span style="font-size:12.0pt">&nbsp;<o:p></o:p></span></font></p>
<p class="e033d674-3a3b-4ac4-8167-2659823254ee"><font size="3" face="Times New Roman"><span style="font-size:12.0pt">&nbsp;<o:p></o:p></span></font></p>
<p class="e033d674-3a3b-4ac4-8167-2659823254ee"><font size="2" color="fuchsia" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:fuchsia">Athena</span></font><font size="1" color="fuchsia" face="Arial"><span style="font-size:7.5pt;font-family:Arial;
color:fuchsia">&reg;</span></font><font size="2" color="fuchsia" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:fuchsia">,
 Created for the Cause</span></font><font size="1" color="fuchsia" face="Arial"><span style="font-size:7.5pt;font-family:Arial;color:fuchsia">&#8482;
</span></font><o:p></o:p></p>
<p class="e033d674-3a3b-4ac4-8167-2659823254ee"><font size="2" face="Arial"><span style="font-size:10.0pt;font-family:Arial">Making a Difference in the Fight Against Breast Cancer</span></font><o:p></o:p></p>
<p class="e033d674-3a3b-4ac4-8167-2659823254ee"><font size="3" face="Times New Roman"><span style="font-size:12.0pt">&nbsp;<o:p></o:p></span></font></p>
<p class="e033d674-3a3b-4ac4-8167-2659823254ee"><font size="3" face="Times New Roman"><span style="font-size:12.0pt">&nbsp;<o:p></o:p></span></font></p>
<p class="e033d674-3a3b-4ac4-8167-2659823254ee"><strong><b><font size="2" face="Arial"><span style="font-size:10.0pt;font-family:Arial">How and Why I Should Support Bottled Water!</span></font></b></strong><b><font size="2" face="Arial"><span style="font-size:10.0pt;font-family:Arial;font-weight:bold"><br>
</span></font></b><font size="2" face="Arial"><span style="font-size:10.0pt;
font-family:Arial">Do not relinquish your right to choose bottled water as a healthy alternative to beverages that contain sugar, calories, etc. Your support of bottled water will
 make a difference! Your signatures count! Go to <a href="http://www.bottledwatermatters.org/luv-bottledwater-iframe/dswaters">
http://www.bottledwatermatters.org/luv-bottledwater-iframe/dswaters</a> and sign a petition to support your right to always choose bottled water. Help fight federal and state issues, such as bottle deposits (or taxes) and organizations that want to ban the
 sale of bottled water. Support community curbside recycling programs. Support bottled water as a healthy way to maintain proper hydration. Our goal is 50,000 signatures. Share this petition with your friends and family today!</span></font><o:p></o:p></p>
<p class="e033d674-3a3b-4ac4-8167-2659823254ee"><font size="3" face="Times New Roman"><span style="font-size:12.0pt">&nbsp;<o:p></o:p></span></font></p>
<p class="e033d674-3a3b-4ac4-8167-2659823254ee"><font size="2" face="Arial"><span style="font-size:10.0pt;font-family:Arial">---------------------------------<br>
CONFIDENTIALITY NOTICE: This e-mail may contain privileged or confidential information and is for the sole use of the intended recipient(s). If you are not the intended recipient, any disclosure, copying, distribution, or use of the contents of this information
 is prohibited and may be unlawful. If you have received this electronic transmission in error, please reply immediately to the sender that you have received the message in error, and delete it. Thank you.<br>
----------------------------------</span></font><font size="1" face="Courier New"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;"><o:p></o:p></span></font></p>
<p><font size="3" face="Times New Roman"><span style="font-size:12.0pt">&nbsp;<o:p></o:p></span></font></p>
</div>
</body>
</html>