<?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: Awk scripting Question in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting-question/m-p/2895161#M719563</link>
    <description>#!/usr/bin/ksh&lt;BR /&gt;#&lt;BR /&gt;awk 'BEGIN { lineno=0; goodlineno=0; }&lt;BR /&gt;{&lt;BR /&gt;   # increment line number&lt;BR /&gt;   lineno+=1;&lt;BR /&gt;   # does it match our pattern?&lt;BR /&gt;   if (match($0,/^matched 1/)) {&lt;BR /&gt;      goodlineno=lineno;&lt;BR /&gt;      print $0;&lt;BR /&gt;   } else {&lt;BR /&gt;      if ((goodlineno) &amp;amp;&amp;amp; (lineno &amp;lt; (goodlineno+11))) {&lt;BR /&gt;         print $0;&lt;BR /&gt;      } else {&lt;BR /&gt;         goodlineno = 0;&lt;BR /&gt;      }&lt;BR /&gt;   }&lt;BR /&gt;}&lt;BR /&gt;'&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Though I think this is a JOB for perl.&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
    <pubDate>Mon, 03 Feb 2003 15:56:14 GMT</pubDate>
    <dc:creator>harry d brown jr</dc:creator>
    <dc:date>2003-02-03T15:56:14Z</dc:date>
    <item>
      <title>Awk scripting Question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting-question/m-p/2895157#M719559</link>
      <description>How can I match a line in a log file "matched 1" and print that line plus the next 10 lines for a report.  The input file will be daily and close to 2.4million lines.  The information will always be in groups of 11</description>
      <pubDate>Mon, 03 Feb 2003 15:35:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting-question/m-p/2895157#M719559</guid>
      <dc:creator>Belinda Dermody</dc:creator>
      <dc:date>2003-02-03T15:35:08Z</dc:date>
    </item>
    <item>
      <title>Re: Awk scripting Question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting-question/m-p/2895158#M719560</link>
      <description>It'll take a while using awk.&lt;BR /&gt;&lt;BR /&gt;cat /tmp/file1 |awk 'BEGIN {found=0;count=0}&lt;BR /&gt;found == 1 &amp;amp;&amp;amp; count &amp;lt; 10 {print $0;count=count+1}&lt;BR /&gt;found == 1 &amp;amp;&amp;amp; count &amp;gt;= 10 {found=0;count=0}&lt;BR /&gt;$1 ~ /matched1/ {found=1;count=1;print $0}&lt;BR /&gt;END'&lt;BR /&gt;&lt;BR /&gt;Share and Enjoy! Ian</description>
      <pubDate>Mon, 03 Feb 2003 15:46:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting-question/m-p/2895158#M719560</guid>
      <dc:creator>Ian Dennison_1</dc:creator>
      <dc:date>2003-02-03T15:46:44Z</dc:date>
    </item>
    <item>
      <title>Re: Awk scripting Question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting-question/m-p/2895159#M719561</link>
      <description>awk '&lt;BR /&gt;/match 1/ {&lt;BR /&gt;print $0;&lt;BR /&gt;for (i=1;i&amp;lt;11;i++) {&lt;BR /&gt;  getline;&lt;BR /&gt;  print $0;&lt;BR /&gt;  }&lt;BR /&gt;}</description>
      <pubDate>Mon, 03 Feb 2003 15:47:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting-question/m-p/2895159#M719561</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2003-02-03T15:47:54Z</dc:date>
    </item>
    <item>
      <title>Re: Awk scripting Question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting-question/m-p/2895160#M719562</link>
      <description>Here's an example that could be adapted (taken from the attached "Handy One-Liners for Sed", courtesy of Princess Paula)&lt;BR /&gt;&lt;BR /&gt;# print 1 line of context before and after regexp, with line number&lt;BR /&gt; # indicating where the regexp occurred (similar to "grep -A1 -B1")&lt;BR /&gt; sed -n -e '/regexp/{=;x;1!p;g;$!N;p;D;}' -e h&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Pete&lt;BR /&gt;</description>
      <pubDate>Mon, 03 Feb 2003 15:49:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting-question/m-p/2895160#M719562</guid>
      <dc:creator>Pete Randall</dc:creator>
      <dc:date>2003-02-03T15:49:07Z</dc:date>
    </item>
    <item>
      <title>Re: Awk scripting Question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting-question/m-p/2895161#M719563</link>
      <description>#!/usr/bin/ksh&lt;BR /&gt;#&lt;BR /&gt;awk 'BEGIN { lineno=0; goodlineno=0; }&lt;BR /&gt;{&lt;BR /&gt;   # increment line number&lt;BR /&gt;   lineno+=1;&lt;BR /&gt;   # does it match our pattern?&lt;BR /&gt;   if (match($0,/^matched 1/)) {&lt;BR /&gt;      goodlineno=lineno;&lt;BR /&gt;      print $0;&lt;BR /&gt;   } else {&lt;BR /&gt;      if ((goodlineno) &amp;amp;&amp;amp; (lineno &amp;lt; (goodlineno+11))) {&lt;BR /&gt;         print $0;&lt;BR /&gt;      } else {&lt;BR /&gt;         goodlineno = 0;&lt;BR /&gt;      }&lt;BR /&gt;   }&lt;BR /&gt;}&lt;BR /&gt;'&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Though I think this is a JOB for perl.&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
      <pubDate>Mon, 03 Feb 2003 15:56:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting-question/m-p/2895161#M719563</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2003-02-03T15:56:14Z</dc:date>
    </item>
    <item>
      <title>Re: Awk scripting Question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting-question/m-p/2895162#M719564</link>
      <description>I agree that perl will be a lot faster, and here is the awk script converted to perl:&lt;BR /&gt;&lt;BR /&gt;#!/opt/perl/bin/perl&lt;BR /&gt;#&lt;BR /&gt;$lineno = 0;&lt;BR /&gt;$goodlineno = 0;&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;    # increment line number&lt;BR /&gt;    $lineno += 1;&lt;BR /&gt;    # does it match our pattern?&lt;BR /&gt;    if ($_ =~ /^matched 1/ ) {&lt;BR /&gt;        $goodlineno = $lineno;&lt;BR /&gt;        print $_;&lt;BR /&gt;    }&lt;BR /&gt;    else {&lt;BR /&gt;        if (($goodlineno) &amp;amp;&amp;amp; ($lineno &amp;lt; ($goodlineno + 11))) {&lt;BR /&gt;            print $_;&lt;BR /&gt;        }&lt;BR /&gt;        else {&lt;BR /&gt;            $goodlineno = 0;&lt;BR /&gt;        }&lt;BR /&gt;    }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
      <pubDate>Mon, 03 Feb 2003 16:04:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting-question/m-p/2895162#M719564</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2003-02-03T16:04:31Z</dc:date>
    </item>
    <item>
      <title>Re: Awk scripting Question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting-question/m-p/2895163#M719565</link>
      <description>Thanks for all the quick responses, Took the fewest lines first to use and it produced the correct output, I haven't checked the others.  What they say, use as little as possible to get the best results.  &lt;BR /&gt;&lt;BR /&gt;Harry Brown, I am just starting to fool around with perl, where do you enter the file name to parse to get your output in the perl program.</description>
      <pubDate>Mon, 03 Feb 2003 16:14:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting-question/m-p/2895163#M719565</guid>
      <dc:creator>Belinda Dermody</dc:creator>
      <dc:date>2003-02-03T16:14:22Z</dc:date>
    </item>
    <item>
      <title>Re: Awk scripting Question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting-question/m-p/2895164#M719566</link>
      <description>Hi James,&lt;BR /&gt;&lt;BR /&gt;here's a perl one-liner:&lt;BR /&gt;&lt;BR /&gt;perl -ne '{$n=11 if /matched 1/;$n--,print $_ if $n;$n=0 if eof}' logfile&lt;BR /&gt;&lt;BR /&gt;Rgds, Robin.</description>
      <pubDate>Mon, 03 Feb 2003 16:14:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting-question/m-p/2895164#M719566</guid>
      <dc:creator>Robin Wakefield</dc:creator>
      <dc:date>2003-02-03T16:14:41Z</dc:date>
    </item>
    <item>
      <title>Re: Awk scripting Question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting-question/m-p/2895165#M719567</link>
      <description>James,&lt;BR /&gt;&lt;BR /&gt;like I would in awk:&lt;BR /&gt;&lt;BR /&gt;cat FILENAME | ./scriptname&lt;BR /&gt;&lt;BR /&gt;Though I really like Robin's solution - quick and easy!&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
      <pubDate>Mon, 03 Feb 2003 16:17:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting-question/m-p/2895165#M719567</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2003-02-03T16:17:52Z</dc:date>
    </item>
    <item>
      <title>Re: Awk scripting Question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting-question/m-p/2895166#M719568</link>
      <description>Robin, that's good! Also catches overlaps. Can be shorter:&lt;BR /&gt;&lt;BR /&gt;perl -ne '/matched 1/&amp;amp;&amp;amp;$n=11;--$n&amp;amp;&amp;amp;print' logfile&lt;BR /&gt;&lt;BR /&gt;Enjoy, have FUN! H.Merijn</description>
      <pubDate>Mon, 03 Feb 2003 16:39:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting-question/m-p/2895166#M719568</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2003-02-03T16:39:21Z</dc:date>
    </item>
    <item>
      <title>Re: Awk scripting Question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting-question/m-p/2895167#M719569</link>
      <description>James,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Here's a comparision of perl vs awk in speed against a file this large:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;# ls -l match.data&lt;BR /&gt;-rw-rw-rw-   1 root       sys        46755563 Feb  3 11:05 match.data&lt;BR /&gt;# wc match.data&lt;BR /&gt;2000000 9866667 46755563 match.data&lt;BR /&gt;# &lt;BR /&gt;&lt;BR /&gt;Robin's perl script using "cat FILENAME | perlscript": &lt;BR /&gt;real     1:11.2&lt;BR /&gt;user       13.7&lt;BR /&gt;sys         9.5&lt;BR /&gt;&lt;BR /&gt;My awk using "cat FILENAME | awkscript":&lt;BR /&gt;real     1:37.1&lt;BR /&gt;user       24.4&lt;BR /&gt;sys        16.3&lt;BR /&gt;&lt;BR /&gt;Robin's perl script using "perlscript FILENAME": &lt;BR /&gt;real     1:11.2&lt;BR /&gt;user       13.7&lt;BR /&gt;sys         9.5&lt;BR /&gt;&lt;BR /&gt;NOW notice that the ABOVE tests sent the OUTPUT to the screen, THESE results below are results when the OUTPUT is  sent to a FILE:&lt;BR /&gt;&lt;BR /&gt;Robin's perl script:&lt;BR /&gt;real       11.4&lt;BR /&gt;user       10.9&lt;BR /&gt;sys         0.3&lt;BR /&gt;&lt;BR /&gt;My AWK script:&lt;BR /&gt;real       20.4&lt;BR /&gt;user       19.7&lt;BR /&gt;sys         0.3&lt;BR /&gt;&lt;BR /&gt;This proves "perl" is almost twice as fast as "awk".&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry&lt;BR /&gt;</description>
      <pubDate>Mon, 03 Feb 2003 16:41:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting-question/m-p/2895167#M719569</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2003-02-03T16:41:47Z</dc:date>
    </item>
  </channel>
</rss>

