<?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 report format query in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-report-format-query/m-p/2875393#M937397</link>
    <description>Ranjit,&lt;BR /&gt;&lt;BR /&gt;Try this awk script:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;awk '&lt;BR /&gt;        { buf[NR] = $0 }&lt;BR /&gt;&lt;BR /&gt;    END {&lt;BR /&gt;           size = NR&lt;BR /&gt;&lt;BR /&gt;           for ( i = 1 ; i &amp;lt;= size ; i++ )&lt;BR /&gt;           {&lt;BR /&gt;                if ( buf[i] ~ /pool$/ )&lt;BR /&gt;                {&lt;BR /&gt;                     pool = buf[i]&lt;BR /&gt;                     j = 0&lt;BR /&gt;                }&lt;BR /&gt;&lt;BR /&gt;                if ( buf[i] ~ /^TAPE[0-9]/ )&lt;BR /&gt;                {&lt;BR /&gt;                     ++j&lt;BR /&gt;                }&lt;BR /&gt;&lt;BR /&gt;                if ( ( buf[i+1] ~ /pool$/ &amp;amp;&amp;amp; pool != "" ) || i == size )&lt;BR /&gt;                {&lt;BR /&gt;                     sum = j&lt;BR /&gt;                     print pool ": " sum&lt;BR /&gt;                }&lt;BR /&gt;           }&lt;BR /&gt;        }' media.out&lt;BR /&gt;&lt;BR /&gt;Change the name of media.out to be the name of your input file.&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;&lt;BR /&gt;Joseph</description>
    <pubDate>Tue, 07 Jan 2003 09:36:21 GMT</pubDate>
    <dc:creator>Joseph A Benaiah_1</dc:creator>
    <dc:date>2003-01-07T09:36:21Z</dc:date>
    <item>
      <title>AWK report format query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-report-format-query/m-p/2875383#M937387</link>
      <description>I have an input file (refer to extract below) which I am attempting to convert into an output file as set-out below.&lt;BR /&gt;&lt;BR /&gt;Is this a task suitable for awk to work on? I have attempted using an approach which searches for the expression "pool" and gets the subsequent TAPE lines - counting each occurance under the respective pool heading.&lt;BR /&gt;&lt;BR /&gt;I've ran into problems and do not get the desired result - in particular the "zero" tape occurances are proving problematic to work around.&lt;BR /&gt;&lt;BR /&gt;Can any one help? Help wound be appreciated.&lt;BR /&gt;&lt;BR /&gt;Thanks in advance.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;=====================================&lt;BR /&gt;INPUT DATA FILE:&lt;BR /&gt;&lt;BR /&gt;TAPE SILO MEDIA INVENTORY&lt;BR /&gt;-------------------------&lt;BR /&gt;&lt;BR /&gt;SALES_BACKUP pool&lt;BR /&gt;&lt;BR /&gt;TAPE0050 &lt;BR /&gt;TAPE0059 &lt;BR /&gt;TAPE0072 &lt;BR /&gt;&lt;BR /&gt;DATABASE_LOG pool&lt;BR /&gt;&lt;BR /&gt;FINANCE pool&lt;BR /&gt;&lt;BR /&gt;TAPE0426 &lt;BR /&gt;TAPE0021 &lt;BR /&gt;&lt;BR /&gt;SCRATCH pool&lt;BR /&gt;&lt;BR /&gt;TAPE0153 &lt;BR /&gt;TAPE0155 &lt;BR /&gt;TAPE0159 &lt;BR /&gt;TAPE0162 &lt;BR /&gt;&lt;BR /&gt;DEVELOPMENT pool&lt;BR /&gt;&lt;BR /&gt;TEST pool&lt;BR /&gt;&lt;BR /&gt;====================================&lt;BR /&gt;&lt;BR /&gt;DESIRED OUTPUT FILE:&lt;BR /&gt;&lt;BR /&gt;SALES_BACKUP pool: 3&lt;BR /&gt;DATABASE_LOG pool: 0&lt;BR /&gt;FINANCE pool:  2&lt;BR /&gt;SCRATCH pool:  4&lt;BR /&gt;DEVELOPMENT pool: 0&lt;BR /&gt;TEST pool:  0&lt;BR /&gt;&lt;BR /&gt;====================================&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 06 Jan 2003 17:59:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-report-format-query/m-p/2875383#M937387</guid>
      <dc:creator>Ranjit_1</dc:creator>
      <dc:date>2003-01-06T17:59:45Z</dc:date>
    </item>
    <item>
      <title>Re: AWK report format query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-report-format-query/m-p/2875384#M937388</link>
      <description>Enter this perl routine into a file (like myprog.pl)-&lt;BR /&gt;&lt;BR /&gt;while(&amp;lt;&amp;gt;) {&lt;BR /&gt; /^(\S+)\s+pool/ &amp;amp;&amp;amp; do { $cur=$1; $cnt{$cur}=0; }&lt;BR /&gt; /^TAPE/ &amp;amp;&amp;amp; do { $cnt{$cur}++; }&lt;BR /&gt;}&lt;BR /&gt;foreach $pool (sort keys %cnt) {&lt;BR /&gt; print "$pool pool: $cnt{$pool}\n";&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Then run passing the input file and output file-&lt;BR /&gt;&lt;BR /&gt;perl myprog.pl yourinput &amp;gt;youroutput&lt;BR /&gt;&lt;BR /&gt;While awk is good for simple text processing, perl is the "king".&lt;BR /&gt;&lt;BR /&gt;HTH&lt;BR /&gt;&lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Mon, 06 Jan 2003 18:16:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-report-format-query/m-p/2875384#M937388</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2003-01-06T18:16:31Z</dc:date>
    </item>
    <item>
      <title>Re: AWK report format query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-report-format-query/m-p/2875385#M937389</link>
      <description>&lt;BR /&gt;&lt;BR /&gt;awk 'BEGIN {firsttime=1;hits=0;prevhit=""}&lt;BR /&gt;{&lt;BR /&gt;if (match($0,/^$/)) {next;}&lt;BR /&gt;if (match($0,/^TAPE[0-9][0-9][0-9][0-9]/)) {hits+=1;}&lt;BR /&gt;if (match($0,/.* pool$/)) {&lt;BR /&gt;   if (firsttime) {firsttime=0;} else {&lt;BR /&gt;      printf("%s pool: %d\n",prevhit,hits);&lt;BR /&gt;      hits=0;&lt;BR /&gt;   }&lt;BR /&gt;   prevhit=$1;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;END {printf("%s pool: %d\n",prevhit,hits);}'&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
      <pubDate>Mon, 06 Jan 2003 18:28:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-report-format-query/m-p/2875385#M937389</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2003-01-06T18:28:45Z</dc:date>
    </item>
    <item>
      <title>Re: AWK report format query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-report-format-query/m-p/2875386#M937390</link>
      <description>Or in a oneliner:&lt;BR /&gt;&lt;BR /&gt;# perl -nle'chomp;/\s+pool$/and$p{$p=$_}=0,next;/\S/&amp;amp;&amp;amp;$p{$p}++}END{print"$_: $p{$_}" for keys%p' infile&lt;BR /&gt;DATABASE_LOG pool: 0&lt;BR /&gt;SALES_BACKUP pool: 3&lt;BR /&gt;FINANCE pool: 2&lt;BR /&gt;DEVELOPMENT pool: 0&lt;BR /&gt;TEST pool: 0&lt;BR /&gt;SCRATCH pool: 4&lt;BR /&gt;</description>
      <pubDate>Mon, 06 Jan 2003 18:30:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-report-format-query/m-p/2875386#M937390</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2003-01-06T18:30:31Z</dc:date>
    </item>
    <item>
      <title>Re: AWK report format query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-report-format-query/m-p/2875387#M937391</link>
      <description>You should be able to use the BEGIN{} section in awk to zero your counters.&lt;BR /&gt;&lt;BR /&gt;For example, &lt;BR /&gt;&lt;BR /&gt;BEGIN{ salespool=0; databasepool=0; financepool=0; scratchpool=0; develpool=0; testpool=0; }{ ...&lt;BR /&gt;&lt;BR /&gt;If you initialize your counters like this, then even the zero ones should come out zero.&lt;BR /&gt;&lt;BR /&gt;good luck,&lt;BR /&gt;&lt;BR /&gt;Vince</description>
      <pubDate>Mon, 06 Jan 2003 18:35:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-report-format-query/m-p/2875387#M937391</guid>
      <dc:creator>Vincent Fleming</dc:creator>
      <dc:date>2003-01-06T18:35:44Z</dc:date>
    </item>
    <item>
      <title>Re: AWK report format query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-report-format-query/m-p/2875388#M937392</link>
      <description>&lt;BR /&gt;Procura,&lt;BR /&gt;&lt;BR /&gt;Your output produced this:&lt;BR /&gt;&lt;BR /&gt;TEST pool: 0&lt;BR /&gt;FINANCE pool: 2&lt;BR /&gt;SALES_BACKUP pool: 3&lt;BR /&gt;: 2&lt;BR /&gt;DATABASE_LOG pool: 0&lt;BR /&gt;DEVELOPMENT pool: 0&lt;BR /&gt;SCRATCH pool: 4&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The : 2 looks bad :-)&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
      <pubDate>Mon, 06 Jan 2003 18:36:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-report-format-query/m-p/2875388#M937392</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2003-01-06T18:36:00Z</dc:date>
    </item>
    <item>
      <title>Re: AWK report format query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-report-format-query/m-p/2875389#M937393</link>
      <description>Vincent,&lt;BR /&gt;&lt;BR /&gt;With the awk I posted it does use a BEGIN and doesn't require temp counters for "pool"'s.&lt;BR /&gt;&lt;BR /&gt;live free or die&lt;BR /&gt;harry</description>
      <pubDate>Mon, 06 Jan 2003 18:37:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-report-format-query/m-p/2875389#M937393</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2003-01-06T18:37:47Z</dc:date>
    </item>
    <item>
      <title>Re: AWK report format query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-report-format-query/m-p/2875390#M937394</link>
      <description>Very true, Harry.  It was just a thought, given that they were having trouble with the zero counters.  &lt;BR /&gt;&lt;BR /&gt;Also... your post wasn't there when I started typing...&lt;BR /&gt;&lt;BR /&gt;I thought the perl solutions were pretty thoughtful - I don't yet think of using perl, as I'm just learning it.  Nice idea, and probably better suited to the task.&lt;BR /&gt;&lt;BR /&gt;I should spend some more time reading up on perl.&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;&lt;BR /&gt;Vince</description>
      <pubDate>Mon, 06 Jan 2003 18:44:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-report-format-query/m-p/2875390#M937394</guid>
      <dc:creator>Vincent Fleming</dc:creator>
      <dc:date>2003-01-06T18:44:22Z</dc:date>
    </item>
    <item>
      <title>Re: AWK report format query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-report-format-query/m-p/2875391#M937395</link>
      <description>Hmm, I just cut-n-pasted his example, and indeed got the output I posted.&lt;BR /&gt;&lt;BR /&gt;Which version of perl do you use? I might have been using the 'for' as a statement modifier, but I don't remember in which version that was introduced.&lt;BR /&gt;&lt;BR /&gt;chopped up for increased readability I did&lt;BR /&gt;&lt;BR /&gt;# perl -nle '&lt;BR /&gt; chomp;&lt;BR /&gt; /\s+pool$/ and $p{$p = $_} = 0, next;&lt;BR /&gt; /\S/ &amp;amp;&amp;amp; $p{$p}++&lt;BR /&gt; }&lt;BR /&gt;END {&lt;BR /&gt; print "$_: $p{$_}" for keys %p&lt;BR /&gt; ' infile&lt;BR /&gt;&lt;BR /&gt;In a `real' script that could look like (but then you could use Rodney's example as well):&lt;BR /&gt;&lt;BR /&gt;--8&amp;lt;---&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;&lt;BR /&gt;my %p = ();&lt;BR /&gt;my $p;&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt; chomp;&lt;BR /&gt; my $p;&lt;BR /&gt; if (/\s+pool$/) {&lt;BR /&gt;  $p{$p = $_} = 0;&lt;BR /&gt;  next;&lt;BR /&gt;  }&lt;BR /&gt; /\S/ and $p{$p}++;&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt;foreach my $k (keys %p) {&lt;BR /&gt; print "$k: $p{$k}";&lt;BR /&gt; }&lt;BR /&gt;--&amp;gt;8---</description>
      <pubDate>Mon, 06 Jan 2003 22:27:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-report-format-query/m-p/2875391#M937395</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2003-01-06T22:27:19Z</dc:date>
    </item>
    <item>
      <title>Re: AWK report format query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-report-format-query/m-p/2875392#M937396</link>
      <description>--8&amp;lt;---&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;&lt;BR /&gt;my %p = ();&lt;BR /&gt;my $p;&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;chomp;&lt;BR /&gt;my $p;  # &amp;lt;---- Strike this line!!&lt;BR /&gt;if (/\s+pool$/) {&lt;BR /&gt;$p{$p = $_} = 0;&lt;BR /&gt;next;&lt;BR /&gt;}&lt;BR /&gt;/\S/ and $p{$p}++;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;foreach my $k (keys %p) {&lt;BR /&gt;print "$k: $p{$k}";&lt;BR /&gt;}&lt;BR /&gt;--&amp;gt;8---</description>
      <pubDate>Mon, 06 Jan 2003 22:29:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-report-format-query/m-p/2875392#M937396</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2003-01-06T22:29:15Z</dc:date>
    </item>
    <item>
      <title>Re: AWK report format query</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-report-format-query/m-p/2875393#M937397</link>
      <description>Ranjit,&lt;BR /&gt;&lt;BR /&gt;Try this awk script:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;awk '&lt;BR /&gt;        { buf[NR] = $0 }&lt;BR /&gt;&lt;BR /&gt;    END {&lt;BR /&gt;           size = NR&lt;BR /&gt;&lt;BR /&gt;           for ( i = 1 ; i &amp;lt;= size ; i++ )&lt;BR /&gt;           {&lt;BR /&gt;                if ( buf[i] ~ /pool$/ )&lt;BR /&gt;                {&lt;BR /&gt;                     pool = buf[i]&lt;BR /&gt;                     j = 0&lt;BR /&gt;                }&lt;BR /&gt;&lt;BR /&gt;                if ( buf[i] ~ /^TAPE[0-9]/ )&lt;BR /&gt;                {&lt;BR /&gt;                     ++j&lt;BR /&gt;                }&lt;BR /&gt;&lt;BR /&gt;                if ( ( buf[i+1] ~ /pool$/ &amp;amp;&amp;amp; pool != "" ) || i == size )&lt;BR /&gt;                {&lt;BR /&gt;                     sum = j&lt;BR /&gt;                     print pool ": " sum&lt;BR /&gt;                }&lt;BR /&gt;           }&lt;BR /&gt;        }' media.out&lt;BR /&gt;&lt;BR /&gt;Change the name of media.out to be the name of your input file.&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;&lt;BR /&gt;Joseph</description>
      <pubDate>Tue, 07 Jan 2003 09:36:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-report-format-query/m-p/2875393#M937397</guid>
      <dc:creator>Joseph A Benaiah_1</dc:creator>
      <dc:date>2003-01-07T09:36:21Z</dc:date>
    </item>
  </channel>
</rss>

