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