<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Yet another awk question... in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/yet-another-awk-question/m-p/3401349#M706248</link>
    <description>Use the "BEGIN" clause within awk.&lt;BR /&gt; &lt;BR /&gt;awk 'BEGIN{print "today is something"};/Start/{x=1;y=0}/Stop/{if (y&amp;gt;3){l[y]="\n"; while(i++&lt;Y&gt;&lt;/Y&gt; &lt;BR /&gt;HTH&lt;BR /&gt; &lt;BR /&gt;-- Rod Hills</description>
    <pubDate>Fri, 15 Oct 2004 15:45:35 GMT</pubDate>
    <dc:creator>Rodney Hills</dc:creator>
    <dc:date>2004-10-15T15:45:35Z</dc:date>
    <item>
      <title>Yet another awk question...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/yet-another-awk-question/m-p/3401348#M706247</link>
      <description>Given:&lt;BR /&gt;&lt;BR /&gt;cat file.txt&lt;BR /&gt;Start&lt;BR /&gt;id fname lname&lt;BR /&gt;-- ----- -----&lt;BR /&gt;1 John Wayne&lt;BR /&gt;2 Bill Smith&lt;BR /&gt;Stop&lt;BR /&gt;Start&lt;BR /&gt;id fname lname&lt;BR /&gt;-- ----- -----&lt;BR /&gt;Stop&lt;BR /&gt;Start&lt;BR /&gt;id fname lname&lt;BR /&gt;-- ----- -----&lt;BR /&gt;1 Mark Williams &lt;BR /&gt;Stop&lt;BR /&gt;&lt;BR /&gt;cat file.awk&lt;BR /&gt;awk '/Start/{x=1;y=0}/Stop/{if (y&amp;gt;3){l[y]="\n"; while(i++&lt;Y&gt;&lt;/Y&gt;&lt;BR /&gt;Outputs:&lt;BR /&gt;&lt;BR /&gt;id fname lname&lt;BR /&gt;-- ----- -----&lt;BR /&gt;1 John Wayne&lt;BR /&gt;2 Bill Smith&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;id fname lname&lt;BR /&gt;-- ----- -----&lt;BR /&gt;1 Mark Williams &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;How do I print a line before the header...  &lt;BR /&gt;&lt;BR /&gt;eg:&lt;BR /&gt;&lt;BR /&gt;This report was run on Sat. May 1, 2005&lt;BR /&gt;id fname lname&lt;BR /&gt;-- ----- -----&lt;BR /&gt;1 John Wayne&lt;BR /&gt;2 Bill Smith&lt;BR /&gt;&lt;BR /&gt;This report was run on Sat. May 1, 2005&lt;BR /&gt;id fname lname&lt;BR /&gt;-- ----- -----&lt;BR /&gt;1 Mark Williams &lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Fri, 15 Oct 2004 15:42:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/yet-another-awk-question/m-p/3401348#M706247</guid>
      <dc:creator>Jamie Collins</dc:creator>
      <dc:date>2004-10-15T15:42:44Z</dc:date>
    </item>
    <item>
      <title>Re: Yet another awk question...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/yet-another-awk-question/m-p/3401349#M706248</link>
      <description>Use the "BEGIN" clause within awk.&lt;BR /&gt; &lt;BR /&gt;awk 'BEGIN{print "today is something"};/Start/{x=1;y=0}/Stop/{if (y&amp;gt;3){l[y]="\n"; while(i++&lt;Y&gt;&lt;/Y&gt; &lt;BR /&gt;HTH&lt;BR /&gt; &lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Fri, 15 Oct 2004 15:45:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/yet-another-awk-question/m-p/3401349#M706248</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2004-10-15T15:45:35Z</dc:date>
    </item>
    <item>
      <title>Re: Yet another awk question...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/yet-another-awk-question/m-p/3401350#M706249</link>
      <description>That produces the following:&lt;BR /&gt;&lt;BR /&gt;today is something&lt;BR /&gt;id fname lname&lt;BR /&gt;-- ----- -----&lt;BR /&gt;1 John Wayne&lt;BR /&gt;2 Bill Smith&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;id fname lname&lt;BR /&gt;-- ----- -----&lt;BR /&gt;1 Mark Williams&lt;BR /&gt;&lt;BR /&gt;Is there a way to get it to print the header every time it sees Start??</description>
      <pubDate>Fri, 15 Oct 2004 15:53:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/yet-another-awk-question/m-p/3401350#M706249</guid>
      <dc:creator>Jamie Collins</dc:creator>
      <dc:date>2004-10-15T15:53:33Z</dc:date>
    </item>
    <item>
      <title>Re: Yet another awk question...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/yet-another-awk-question/m-p/3401351#M706250</link>
      <description>Whoops, I didn't notice you had it before everyline that starts with "id".&lt;BR /&gt; &lt;BR /&gt;Just add an "if" statement- &lt;BR /&gt; &lt;BR /&gt;awk '/Start/{x=1;y=0}/Stop/{if (y&amp;gt;3){l[y]="\n"; while(i++&lt;Y&gt;&lt;/Y&gt; &lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Fri, 15 Oct 2004 15:55:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/yet-another-awk-question/m-p/3401351#M706250</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2004-10-15T15:55:06Z</dc:date>
    </item>
    <item>
      <title>Re: Yet another awk question...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/yet-another-awk-question/m-p/3401352#M706251</link>
      <description>/Start/{x=1;y=0}/Stop/{if (y&amp;gt;3){l[y]="\n"; while(i++&lt;Y&gt;&lt;/Y&gt;}&lt;BR /&gt;&lt;BR /&gt;produces:&lt;BR /&gt;&lt;BR /&gt;This report was run on Sat May 1, 2005&lt;BR /&gt;This report was run on Sat May 1, 2005&lt;BR /&gt;This report was run on Sat May 1, 2005&lt;BR /&gt;This report was run on Sat May 1, 2005&lt;BR /&gt;This report was run on Sat May 1, 2005&lt;BR /&gt;Start fname lname&lt;BR /&gt;Start ----- -----&lt;BR /&gt;Start John Wayne&lt;BR /&gt;Start Bill Smith&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;This report was run on Sat May 1, 2005&lt;BR /&gt;This report was run on Sat May 1, 2005&lt;BR /&gt;This report was run on Sat May 1, 2005&lt;BR /&gt;This report was run on Sat May 1, 2005&lt;BR /&gt;This report was run on Sat May 1, 2005&lt;BR /&gt;This report was run on Sat May 1, 2005&lt;BR /&gt;This report was run on Sat May 1, 2005&lt;BR /&gt;This report was run on Sat May 1, 2005&lt;BR /&gt;This report was run on Sat May 1, 2005&lt;BR /&gt;Start fname lname&lt;BR /&gt;Start ----- -----&lt;BR /&gt;Start Mark Williams&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;This report was run on Sat May 1, 2005&lt;BR /&gt;This report was run on Sat May 1, 2005&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 15 Oct 2004 16:00:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/yet-another-awk-question/m-p/3401352#M706251</guid>
      <dc:creator>Jamie Collins</dc:creator>
      <dc:date>2004-10-15T16:00:03Z</dc:date>
    </item>
    <item>
      <title>Re: Yet another awk question...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/yet-another-awk-question/m-p/3401353#M706252</link>
      <description>Whoops again.&lt;BR /&gt; &lt;BR /&gt;If you want it printed when "Start" is found, why not add it their.&lt;BR /&gt; &lt;BR /&gt;awk '/Start/{x=1;y=0; print "This report was run on Sat May 1,2005"}/Stop/{if (y&amp;gt;3){l[y]="\n"; while(i++&lt;Y&gt;&lt;/Y&gt; &lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Fri, 15 Oct 2004 16:02:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/yet-another-awk-question/m-p/3401353#M706252</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2004-10-15T16:02:11Z</dc:date>
    </item>
    <item>
      <title>Re: Yet another awk question...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/yet-another-awk-question/m-p/3401354#M706253</link>
      <description>That works good except when I encounter the blank line:&lt;BR /&gt;&lt;BR /&gt;id fname lname&lt;BR /&gt;-- ----- -----&lt;BR /&gt;&lt;BR /&gt;It still prints the header line...&lt;BR /&gt;&lt;BR /&gt;This report was run on Sat May 1, 2005&lt;BR /&gt;id fname lname&lt;BR /&gt;-- ----- -----&lt;BR /&gt;1 John Wayne&lt;BR /&gt;2 Bill Smith&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;This report was run on Sat May 1, 2005&lt;BR /&gt;This report was run on Sat May 1, 2005&lt;BR /&gt;id fname lname&lt;BR /&gt;-- ----- -----&lt;BR /&gt;1 Mark Williams&lt;BR /&gt;&lt;BR /&gt;Maybe a nested if would work?</description>
      <pubDate>Fri, 15 Oct 2004 16:06:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/yet-another-awk-question/m-p/3401354#M706253</guid>
      <dc:creator>Jamie Collins</dc:creator>
      <dc:date>2004-10-15T16:06:47Z</dc:date>
    </item>
    <item>
      <title>Re: Yet another awk question...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/yet-another-awk-question/m-p/3401355#M706254</link>
      <description>awk '/Start/{x=1;y=0}/Stop/{if (y&amp;gt;3){l[y]="\n"; print "hello"; while(i++&lt;Y&gt;&lt;/Y&gt;&lt;BR /&gt;Ah, a continuation of an earlier threat.&lt;BR /&gt;That solution came form me.&lt;BR /&gt;When it sees 'start', it merely starts counting and remembering&lt;BR /&gt;When it sees 'stop' AND has seen enough lines it starts to dump its memory with a while loop.&lt;BR /&gt;&lt;BR /&gt;So, for this new requirement you need to add a print in the 'stop' section, just before executing the while... print.&lt;BR /&gt;As per above.&lt;BR /&gt;&lt;BR /&gt;In more readable form:&lt;BR /&gt;&lt;BR /&gt;awk '&lt;BR /&gt;/Start/{x=1;y=0}&lt;BR /&gt;/Stop/ {if (y&amp;gt;3) {&lt;BR /&gt;   l[y]="\n"; &lt;BR /&gt;   print "hello"; &lt;BR /&gt;   while(i++&lt;Y&gt;&lt;/Y&gt;   }&lt;BR /&gt;   x=i=0&lt;BR /&gt;   }&lt;BR /&gt;{l[y]=$0;&lt;BR /&gt; y+=x}&lt;BR /&gt;'&lt;BR /&gt;&lt;BR /&gt;As an alternative you can also overwrite the 'start' line with the desired header, and have the while loop print it out eventually by tweaking its start and end:&lt;BR /&gt;&lt;BR /&gt;awk '/Start/{x=1;y=0;$0="hello"}/Stop/{if (y&amp;gt;3){l[y]="\n"; while(i&amp;lt;=y){print l[i++]}};x=i=0}{l[y]=$0;y+=x}'&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Hein&lt;BR /&gt;</description>
      <pubDate>Fri, 15 Oct 2004 21:51:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/yet-another-awk-question/m-p/3401355#M706254</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-10-15T21:51:08Z</dc:date>
    </item>
    <item>
      <title>Re: Yet another awk question...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/yet-another-awk-question/m-p/3401356#M706255</link>
      <description>awk 'BEGIN{ print "what ever you want"}; ....'&lt;BR /&gt;&lt;BR /&gt;or pribably a better solution is&lt;BR /&gt;&lt;BR /&gt;perl -ane 'INIT{print "hello world"}; if(/Start/ .. /Stop/) { print "@F\n"}' &lt;INPUT file="" /&gt;&lt;BR /&gt;&lt;BR /&gt;but I've recently decided to ditch awk for perl...&lt;BR /&gt;&lt;BR /&gt;Tim</description>
      <pubDate>Sat, 16 Oct 2004 04:48:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/yet-another-awk-question/m-p/3401356#M706255</guid>
      <dc:creator>Tim D Fulford</dc:creator>
      <dc:date>2004-10-16T04:48:50Z</dc:date>
    </item>
    <item>
      <title>Re: Yet another awk question...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/yet-another-awk-question/m-p/3401357#M706256</link>
      <description>We can get your required output as,&lt;BR /&gt;&lt;BR /&gt;# awk '/Start/{x=1;y=0}/Stop/{if (y&amp;gt;3){l[y]="\n"; if ($l[1]="id") { print "This report was run on Sat. May 1, 2005" }&lt;BR /&gt;&amp;gt; while(i++&lt;Y&gt;&lt;/Y&gt;This report was run on Sat. May 1, 2005&lt;BR /&gt;id fname lname&lt;BR /&gt;-- ----- -----&lt;BR /&gt;1 John Wayne&lt;BR /&gt;2 Bill Smith&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;This report was run on Sat. May 1, 2005&lt;BR /&gt;id fname lname&lt;BR /&gt;-- ----- -----&lt;BR /&gt;1 Mark Williams&lt;BR /&gt;&lt;BR /&gt;HTH.</description>
      <pubDate>Sat, 16 Oct 2004 12:34:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/yet-another-awk-question/m-p/3401357#M706256</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2004-10-16T12:34:44Z</dc:date>
    </item>
  </channel>
</rss>

