<?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 problem...any hints?? in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-any-hints/m-p/3816369#M780625</link>
    <description>thanks everyone for help..that help me solve my problem :)&lt;BR /&gt;&lt;BR /&gt;cheers,</description>
    <pubDate>Tue, 04 Jul 2006 02:14:34 GMT</pubDate>
    <dc:creator>amonamon</dc:creator>
    <dc:date>2006-07-04T02:14:34Z</dc:date>
    <item>
      <title>awk problem...any hints??</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-any-hints/m-p/3816363#M780619</link>
      <description>Hello I have one problem..&lt;BR /&gt;&lt;BR /&gt;I have fileA:&lt;BR /&gt;&lt;BR /&gt;value1  1&lt;BR /&gt;value2  3&lt;BR /&gt;value3  4&lt;BR /&gt;value1  9&lt;BR /&gt;value2  5&lt;BR /&gt;value5  5&lt;BR /&gt;value1  2&lt;BR /&gt;value4  1&lt;BR /&gt;...&lt;BR /&gt;..&lt;BR /&gt;...&lt;BR /&gt;..&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I wanted file  like this:&lt;BR /&gt;&lt;BR /&gt;fileB:&lt;BR /&gt;value1  12  3&lt;BR /&gt;value2  3   2&lt;BR /&gt;value3  4   4&lt;BR /&gt;value4  1   1&lt;BR /&gt;value5  5   1  &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;where I do not have douplicates anymore and second column is sum of values for each value and 3. column is number each same record shows in file&lt;BR /&gt;&lt;BR /&gt;for example in fileA  3 times value1 records is shown..&lt;BR /&gt;vale2 is 2 times shown in fileA and 2 solumn in fileB meand that total values for value1 is 12&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;any hints?</description>
      <pubDate>Mon, 03 Jul 2006 08:17:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-any-hints/m-p/3816363#M780619</guid>
      <dc:creator>amonamon</dc:creator>
      <dc:date>2006-07-03T08:17:20Z</dc:date>
    </item>
    <item>
      <title>Re: awk problem...any hints??</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-any-hints/m-p/3816364#M780620</link>
      <description># perl -le'/^(\S+)\s+(\S+)/&amp;amp;&amp;amp;push%{$v{$1}},$2}END{print"$_:@{$v{$_}}"for sort keys%v' fileA&lt;BR /&gt;&lt;BR /&gt;untested&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
      <pubDate>Mon, 03 Jul 2006 08:33:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-any-hints/m-p/3816364#M780620</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2006-07-03T08:33:54Z</dc:date>
    </item>
    <item>
      <title>Re: awk problem...any hints??</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-any-hints/m-p/3816365#M780621</link>
      <description>woowww...I understand nothing here...:) but thanks for answer..is ther a way to to that with awk?? &lt;BR /&gt;I am newbie here..</description>
      <pubDate>Mon, 03 Jul 2006 08:35:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-any-hints/m-p/3816365#M780621</guid>
      <dc:creator>amonamon</dc:creator>
      <dc:date>2006-07-03T08:35:42Z</dc:date>
    </item>
    <item>
      <title>Re: awk problem...any hints??</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-any-hints/m-p/3816366#M780622</link>
      <description>And wrong also. Small typo.&lt;BR /&gt;&lt;BR /&gt;lt09:/home/merijn 106 &amp;gt; perl -nle'/^(\S+)\s+(\S+)/&amp;amp;&amp;amp;push@{$v{$1}},$2;}END{print"$_:@{$v{$_}}"for sort keys%v' fileA&lt;BR /&gt;value1:1 9 2&lt;BR /&gt;value2:3 5&lt;BR /&gt;value3:4&lt;BR /&gt;value4:1&lt;BR /&gt;value5:5&lt;BR /&gt;lt09:/home/merijn 107 &amp;gt;&lt;BR /&gt;&lt;BR /&gt;My awk foo lets me down on this, but lemme try to explain what I did&lt;BR /&gt;&lt;BR /&gt;&amp;gt; perl -nle&lt;BR /&gt;&lt;BR /&gt;-n process for every line, but do not print&lt;BR /&gt;-l add a newline to every printed line&lt;BR /&gt;-e the `script' expression&lt;BR /&gt;&lt;BR /&gt;&amp;gt; /^(\S+)\s+(\S+)/&lt;BR /&gt;&lt;BR /&gt;match the line as&lt;BR /&gt;&lt;BR /&gt;^ start of line&lt;BR /&gt;(\S+) non-whitespace (as many as matched. The parens capture the result in $1 (e.g. value1)&lt;BR /&gt;\s+ whitespace&lt;BR /&gt;(\S+) non-whitespace (e.g. 12)&lt;BR /&gt;&lt;BR /&gt;&amp;gt; &amp;amp;&amp;amp; push @{$v{$1}}, $2;&lt;BR /&gt;&lt;BR /&gt;if it matches, push the second arg $2 onto a list grouped in hash %v (which is just a short arbitrary name) indexed with the value from $1&lt;BR /&gt;&lt;BR /&gt;&amp;gt; } END {&lt;BR /&gt;&lt;BR /&gt;That is a bit mean. You should know about how perl invokes with -n and -p to use this, but effectively, the next block is only invoked after all input is processed&lt;BR /&gt;&lt;BR /&gt;&amp;gt; print "$_:@{$v{$_}}" for sort keys%v&lt;BR /&gt;&lt;BR /&gt;the keys of the hash are the values found, which we iterate over with for keys %v&lt;BR /&gt;Those keys are processed by sort and then used in the print&lt;BR /&gt;the print prints the key (the value from fileA), and the list of numebrs collected in the process after that. The calling -l option will add a newline&lt;BR /&gt;&lt;BR /&gt;Hopes that might motivate you to use perl more often&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
      <pubDate>Mon, 03 Jul 2006 08:59:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-any-hints/m-p/3816366#M780622</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2006-07-03T08:59:07Z</dc:date>
    </item>
    <item>
      <title>Re: awk problem...any hints??</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-any-hints/m-p/3816367#M780623</link>
      <description>amonamon,&lt;BR /&gt;&lt;BR /&gt;Here's an awk script I wrote that totals a day's worth of sessions from Oracle's listener.log (after it's run through 'sed').  It it very similar to what you're looking for, and should be relatively easy to  modify:&lt;BR /&gt;&lt;BR /&gt;# more acc.awk&lt;BR /&gt;BEGIN {&lt;BR /&gt;        FS=","&lt;BR /&gt;        hr=-1&lt;BR /&gt;        d=-1&lt;BR /&gt;        ptr=0&lt;BR /&gt;}&lt;BR /&gt;{&lt;BR /&gt;        if (hr==-1 || hr==$2)&lt;BR /&gt;        {&lt;BR /&gt;                if (nb[$3]==null)&lt;BR /&gt;                {&lt;BR /&gt;                        na[ptr]=$3&lt;BR /&gt;                        ptr++&lt;BR /&gt;                }&lt;BR /&gt;                nb[$3]++&lt;BR /&gt;        }&lt;BR /&gt;        else&lt;BR /&gt;        {&lt;BR /&gt;                printf("********* %d:00 to %d:59 on %s *********\n",hr,hr,d)&lt;BR /&gt;                for (i=0; i&lt;PTR&gt;&lt;/PTR&gt;                {&lt;BR /&gt;                        printf("%30s\t\t%d\n",na[i],nb[na[i]])&lt;BR /&gt;                }&lt;BR /&gt;                for (i in na)&lt;BR /&gt;                        delete na[i]&lt;BR /&gt;                for (i in nb)&lt;BR /&gt;                        delete nb[i]&lt;BR /&gt;                ptr=0&lt;BR /&gt;        }&lt;BR /&gt;        d=$1&lt;BR /&gt;        hr=$2&lt;BR /&gt;}&lt;BR /&gt;END {&lt;BR /&gt;                printf("********* %d:00 to %d:59 on %s *********\n",hr,hr,$1)&lt;BR /&gt;                for (i=0; i&lt;PTR&gt;&lt;/PTR&gt;                {&lt;BR /&gt;                        printf("%30s\t\t%d\n",na[i],nb[na[i]])&lt;BR /&gt;                }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;It gives output of the form:&lt;BR /&gt;&lt;BR /&gt;********* 6:00 to 6:59 on 03-JUL *********&lt;BR /&gt;                        user2          7                          &lt;BR /&gt;                        oracle  14&lt;BR /&gt;                        user1           10</description>
      <pubDate>Mon, 03 Jul 2006 11:31:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-any-hints/m-p/3816367#M780623</guid>
      <dc:creator>spex</dc:creator>
      <dc:date>2006-07-03T11:31:25Z</dc:date>
    </item>
    <item>
      <title>Re: awk problem...any hints??</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-any-hints/m-p/3816368#M780624</link>
      <description>Hello amonamon...here's an awk construct that does what you're looking for:&lt;BR /&gt;&lt;BR /&gt;# awk '{x[$1]++;z[$1]+=$2} END{for(i in x) print i,z[i],x[i]}' fileA &amp;gt; fileB&lt;BR /&gt;&lt;BR /&gt;~cheers</description>
      <pubDate>Mon, 03 Jul 2006 12:24:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-any-hints/m-p/3816368#M780624</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2006-07-03T12:24:06Z</dc:date>
    </item>
    <item>
      <title>Re: awk problem...any hints??</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-any-hints/m-p/3816369#M780625</link>
      <description>thanks everyone for help..that help me solve my problem :)&lt;BR /&gt;&lt;BR /&gt;cheers,</description>
      <pubDate>Tue, 04 Jul 2006 02:14:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-problem-any-hints/m-p/3816369#M780625</guid>
      <dc:creator>amonamon</dc:creator>
      <dc:date>2006-07-04T02:14:34Z</dc:date>
    </item>
  </channel>
</rss>

