Cool.  I really have to get with the program and put some stuff on github.<br><br><div class="gmail_quote">On Thu, Mar 29, 2012 at 12:29 AM, Richard Bronosky <span dir="ltr">&lt;<a href="mailto:Richard@bronosky.com">Richard@bronosky.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Sadly, I only know &quot;of&quot; ed. But, thanks to you, Ed, I&#39;m now interested<br>
in using ed in my daily workflow. I like this particular use case.<br>
I&#39;ve added it to my gist.<br>
<a href="https://gist.github.com/2228256#file_flop2.sh" target="_blank">https://gist.github.com/2228256#file_flop2.sh</a> (I &lt;3 heredoc syntax)<br>
<div><div class="h5"><br>
On Wed, Mar 28, 2012 at 9:57 PM, Ed Cashin &lt;<a href="mailto:ecashin@noserose.net">ecashin@noserose.net</a>&gt; wrote:<br>
&gt; Thanks for mentioning the non-stream editor!  They made sed for streams,<br>
&gt; because ed is for files.  It is at times like this when I sincerely regret<br>
&gt; the way distros are beginning to omit ed for the first time in decades.<br>
&gt;<br>
&gt; There&#39;s an ed move command called &quot;m&quot;.  Move this line to that line.  The<br>
&gt; one liner below does the same thing as this interactive session<br>
&gt;<br>
&gt; $m0<br>
&gt; w<br>
&gt; q<br>
&gt;<br>
&gt; ecashin@reynolds:~$ head /etc/passwd | nl &gt; ~/tmp/a<br>
&gt; ecashin@reynolds:~$ cp ~/tmp/a ~/tmp/b<br>
&gt; ecashin@reynolds:~$ printf &#39;$m0\nw\nq\n&#39; | ed ~/tmp/b<br>
&gt; 414<br>
&gt; 414<br>
&gt; ecashin@reynolds:~$ diff -u ~/tmp/a ~/tmp/b<br>
&gt; --- /home/ecashin/tmp/a 2012-03-28 21:40:25.000000000 -0400<br>
&gt; +++ /home/ecashin/tmp/b 2012-03-28 21:41:44.000000000 -0400<br>
&gt; @@ -1,3 +1,4 @@<br>
&gt; +    10 news:x:9:9:news:/var/spool/news:/bin/sh<br>
&gt;       1 root:x:0:0:root:/root:/bin/bash<br>
&gt;       2 daemon:x:1:1:daemon:/usr/sbin:/bin/sh<br>
&gt;       3 bin:x:2:2:bin:/bin:/bin/sh<br>
&gt; @@ -7,4 +8,3 @@<br>
&gt;       7 man:x:6:12:man:/var/cache/man:/bin/sh<br>
&gt;       8 lp:x:7:7:lp:/var/spool/lpd:/bin/sh<br>
&gt;       9 mail:x:8:8:mail:/var/mail:/bin/sh<br>
&gt; -    10 news:x:9:9:news:/var/spool/news:/bin/sh<br>
&gt; ecashin@reynolds:~$<br>
&gt;<br>
&gt; On Wed, Mar 28, 2012 at 12:41 PM, Richard Bronosky &lt;<a href="mailto:Richard@bronosky.com">Richard@bronosky.com</a>&gt;<br>
&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; Be careful doing this with large files. You are storing the whole file<br>
&gt;&gt; in memory.<br>
&gt;&gt;<br>
&gt;&gt; I would do this in 2 passes.<br>
&gt;&gt;<br>
&gt;&gt; # First get the last line into a new file. (assuming the file in<br>
&gt;&gt; question is passed in as the first argument)<br>
&gt;&gt; tail -n1 $1 &gt; $1.mod<br>
&gt;&gt; # Second add the rest of the file, less the last line.<br>
&gt;&gt; sed &#39;$d&#39; $1 &gt;&gt; $1.mod<br>
&gt;&gt;<br>
&gt;&gt; This is working with streams. It requires an additional $filesize of<br>
&gt;&gt; disk space, but it does not require $filesize of RAM.<br>
&gt;&gt;<br>
&gt;&gt; If you want to be really efficient, use ed. ;-)<br>
&gt;&gt; # This will trim the last line of the file in place, but I&#39;m not<br>
&gt;&gt; taking the time to figure out how to add it to the beginning.<br>
&gt;&gt; ed &quot;$1&quot; &lt;&lt; EOF<br>
&gt;&gt; $<br>
&gt;&gt; d<br>
&gt;&gt; w<br>
&gt;&gt; EOF<br>
&gt;&gt;<br>
&gt;&gt; On Mar 28, 2012 11:19 AM, &quot;Lightner, Jeff&quot; &lt;<a href="mailto:JLightner@water.com">JLightner@water.com</a>&gt; wrote:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; I found this works:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; awk &#39;{a[NR]=$0} END {print a[NR]; for (i=1;i&lt;NR;i++) print a[i]}&#39;<br>
&gt;&gt; &gt; originalfile &gt;newfile<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Where you replace originalfile and newfile with real file names.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; ________________________________<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; From: <a href="mailto:ale-bounces@ale.org">ale-bounces@ale.org</a> [mailto:<a href="mailto:ale-bounces@ale.org">ale-bounces@ale.org</a>] On Behalf Of<br>
&gt;&gt; &gt; Lightner, Jeff<br>
&gt;&gt; &gt; Sent: Wednesday, March 28, 2012 11:10 AM<br>
&gt;&gt; &gt; To: Atlanta Linux Enthusiasts<br>
&gt;&gt; &gt; Subject: [ale] Move last line of a file to first line<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; We have variable length text files being received in which the “header”<br>
&gt;&gt; &gt; line we use in automated processing is the last line of the file rather than<br>
&gt;&gt; &gt; the first line.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; What is the best way to move that last line of a text file to be the<br>
&gt;&gt; &gt; first line?<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Please answer the question as asked and don’t suggest making the file be<br>
&gt;&gt; &gt; in the correct order when we receive it or changing the automated processing<br>
&gt;&gt; &gt; to read the last line first.  Assume those aren’t options.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; What I came up with was to do tail -1 &gt;newfile and head -&lt;number of<br>
&gt;&gt; &gt; lines – 1&gt; but was thinking there ought to be a better way.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; I see sed can deal with last line, first line and insertion but the<br>
&gt;&gt; &gt; examples I’m finding address either/or not moving last line to first line.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Athena®, Created for the Cause™<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Making a Difference in the Fight Against Breast Cancer<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; How and Why I Should Support Bottled Water!<br>
&gt;&gt; &gt; Do not relinquish your right to choose bottled water as a healthy<br>
&gt;&gt; &gt; alternative to beverages that contain sugar, calories, etc. Your support of<br>
&gt;&gt; &gt; bottled water will make a difference! Your signatures count! Go to<br>
&gt;&gt; &gt; <a href="http://www.bottledwatermatters.org/luv-bottledwater-iframe/dswaters" target="_blank">http://www.bottledwatermatters.org/luv-bottledwater-iframe/dswaters</a> and sign<br>
&gt;&gt; &gt; a petition to support your right to always choose bottled water. Help fight<br>
&gt;&gt; &gt; federal and state issues, such as bottle deposits (or taxes) and<br>
&gt;&gt; &gt; organizations that want to ban the sale of bottled water. Support community<br>
&gt;&gt; &gt; curbside recycling programs. Support bottled water as a healthy way to<br>
&gt;&gt; &gt; maintain proper hydration. Our goal is 50,000 signatures. Share this<br>
&gt;&gt; &gt; petition with your friends and family today!<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; ---------------------------------<br>
&gt;&gt; &gt; CONFIDENTIALITY NOTICE: This e-mail may contain privileged or<br>
&gt;&gt; &gt; confidential information and is for the sole use of the intended<br>
&gt;&gt; &gt; recipient(s). If you are not the intended recipient, any disclosure,<br>
&gt;&gt; &gt; copying, distribution, or use of the contents of this information is<br>
&gt;&gt; &gt; prohibited and may be unlawful. If you have received this electronic<br>
&gt;&gt; &gt; transmission in error, please reply immediately to the sender that you have<br>
&gt;&gt; &gt; received the message in error, and delete it. Thank you.<br>
&gt;&gt; &gt; ----------------------------------<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; _______________________________________________<br>
&gt;&gt; &gt; Ale mailing list<br>
&gt;&gt; &gt; <a href="mailto:Ale@ale.org">Ale@ale.org</a><br>
&gt;&gt; &gt; <a href="http://mail.ale.org/mailman/listinfo/ale" target="_blank">http://mail.ale.org/mailman/listinfo/ale</a><br>
&gt;&gt; &gt; See JOBS, ANNOUNCE and SCHOOLS lists at<br>
&gt;&gt; &gt; <a href="http://mail.ale.org/mailman/listinfo" target="_blank">http://mail.ale.org/mailman/listinfo</a><br>
&gt;&gt; &gt;<br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; Ale mailing list<br>
&gt;&gt; <a href="mailto:Ale@ale.org">Ale@ale.org</a><br>
&gt;&gt; <a href="http://mail.ale.org/mailman/listinfo/ale" target="_blank">http://mail.ale.org/mailman/listinfo/ale</a><br>
&gt;&gt; See JOBS, ANNOUNCE and SCHOOLS lists at<br>
&gt;&gt; <a href="http://mail.ale.org/mailman/listinfo" target="_blank">http://mail.ale.org/mailman/listinfo</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt;   Ed Cashin &lt;<a href="mailto:ecashin@noserose.net">ecashin@noserose.net</a>&gt;<br>
&gt;   <a href="http://noserose.net/e/" target="_blank">http://noserose.net/e/</a><br>
&gt;   <a href="http://www.coraid.com/" target="_blank">http://www.coraid.com/</a><br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Ale mailing list<br>
&gt; <a href="mailto:Ale@ale.org">Ale@ale.org</a><br>
&gt; <a href="http://mail.ale.org/mailman/listinfo/ale" target="_blank">http://mail.ale.org/mailman/listinfo/ale</a><br>
&gt; See JOBS, ANNOUNCE and SCHOOLS lists at<br>
&gt; <a href="http://mail.ale.org/mailman/listinfo" target="_blank">http://mail.ale.org/mailman/listinfo</a><br>
&gt;<br>
<br>
<br>
<br>
--<br>
</div></div>.!# RichardBronosky #!.<br>
<div class="HOEnZb"><div class="h5"><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>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>  Ed Cashin &lt;<a href="mailto:ecashin@noserose.net">ecashin@noserose.net</a>&gt;<br>  <a href="http://noserose.net/e/">http://noserose.net/e/</a><br>  <a href="http://www.coraid.com/">http://www.coraid.com/</a><br>