<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:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@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","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-CA link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>The AWK version is functionally identical, and not very much shorter, or any more elegant:<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>    awk ‘/output start/ {s=1};{if (s==1) print $0};/output end/ {s=0}’<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>(the perl version can generally be made that small, too.)<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I would instead suggest sed(1), since this is precisely what it’s designed for:<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>    sed –n ‘/output start/,/output end/p’ &lt; infile<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>-Adam<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><a name="_MailEndCompose"><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p>&nbsp;</o:p></span></a></p><div style='border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt'><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> roundtable-bounces@muug.mb.ca [mailto:roundtable-bounces@muug.mb.ca] <b>On Behalf Of </b>Sean Walberg<br><b>Sent:</b> Wednesday, November 10, 2010 10:56<br><b>To:</b> Continuation of Round Table discussion<br><b>Subject:</b> Re: [RndTbl] Command line challenge: trim garbage from start and end of a file.<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal>OTTOMH:<o:p></o:p></p><div><p class=MsoNormal><o:p>&nbsp;</o:p></p></div><div><p class=MsoNormal style='margin-bottom:12.0pt'>perl -n -e 'BEGIN {$state = 0} $state = 1 if ($state == 0 and /output start/); $state = 2 if ($state == 1 and /output end/) &nbsp;; print if ($state == 1)' &lt; infile &gt; outfile<o:p></o:p></p></div><div><p class=MsoNormal>I'll bet there's a shorter AWK version though.<o:p></o:p></p></div><div><p class=MsoNormal><o:p>&nbsp;</o:p></p></div><div><p class=MsoNormal>Sean<o:p></o:p></p></div><div><p class=MsoNormal><o:p>&nbsp;</o:p></p><div><p class=MsoNormal>On Wed, Nov 10, 2010 at 10:51 AM, John Lange &lt;<a href="mailto:john@johnlange.ca">john@johnlange.ca</a>&gt; wrote:<o:p></o:p></p><p class=MsoNormal>I have files with the following structure:<br><br>garbage<br>garbage<br>garbage<br>output start<br>.. good data<br>.. good data<br>.. good data<br>.. good data<br>output end<br>garbage<br>garbage<br>garbage<br><br>How can I extract the good data from the file trimming the garbage<br>from the beginning and end?<br><br>The following works just fine but it's dirty because I don't like the<br>fact that I have to pick an arbitrarily large number for the &quot;before&quot;<br>and &quot;after&quot; values.<br><br>grep -A 999999 &quot;output start&quot; &lt;infile&gt; | grep -B 999999 &quot;output end&quot; &gt; newfile<br><br>Can anyone come up with something more elegant?<br><span style='color:#888888'><br>--<br>John Lange<br><a href="http://www.johnlange.ca" target="_blank">www.johnlange.ca</a><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></span><o:p></o:p></p></div><p class=MsoNormal><br><br clear=all><br>-- <br>Sean Walberg &lt;<a href="mailto:sean@ertw.com">sean@ertw.com</a>&gt;&nbsp; &nbsp; <a href="http://ertw.com/">http://ertw.com/</a><o:p></o:p></p></div></div></div></body></html>