<?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: script question in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/4907296#M838296</link>
    <description>for SSN in `cat $WORKFILE | awk {'print $1'} |uniq`&lt;BR /&gt;do&lt;BR /&gt;grep $SSN $WORKFILE &amp;gt; /tmp/sometempfile&lt;BR /&gt;tot=0&lt;BR /&gt;cat /tmp/sometempfile|while read SSN HOURS&lt;BR /&gt;do&lt;BR /&gt;let tot=$tot+$HOURS&lt;BR /&gt;done&lt;BR /&gt;echo $SSN" has "$tot" total hours"&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;hope this helps&lt;BR /&gt;</description>
    <pubDate>Tue, 14 Jun 2005 15:37:49 GMT</pubDate>
    <dc:creator>Mel Burslan</dc:creator>
    <dc:date>2005-06-14T15:37:49Z</dc:date>
    <item>
      <title>script question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/4907294#M838294</link>
      <description>I would like to be able to read a file with two columns and add all of the values in the second column, where the values in the first column are equal...&lt;BR /&gt;&lt;BR /&gt;I started like this...&lt;BR /&gt;***&lt;BR /&gt;sort /usr/contrib/scripts/example &amp;gt;&amp;gt;$WORKPATH/$WORKFILE&lt;BR /&gt;cat $WORKPATH/$WORKFILE |while read SSN HOURS&lt;BR /&gt;do &lt;BR /&gt; let TOTAL=TOTAL+HOURS&lt;BR /&gt;echo $SSN $HOURS$TOTAL &amp;gt;&amp;gt; $WORKPATH/example.totals&lt;BR /&gt;done&lt;BR /&gt;***&lt;BR /&gt;I dont really need the total, just sub-totals by the first field - Any ideas are greatly appreciated.&lt;BR /&gt;</description>
      <pubDate>Tue, 14 Jun 2005 15:22:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/4907294#M838294</guid>
      <dc:creator>Michael Treacy</dc:creator>
      <dc:date>2005-06-14T15:22:04Z</dc:date>
    </item>
    <item>
      <title>Re: script question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/4907295#M838295</link>
      <description>total=$(awk '{s+=$2}' "your_file")&lt;BR /&gt;&lt;BR /&gt;for i in $(cat "your_file"|awk '{print $1}')&lt;BR /&gt;do&lt;BR /&gt;if [[ ${i} = ${total} ]]&lt;BR /&gt;then&lt;BR /&gt;echo "$i = ${total}"&lt;BR /&gt;fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Anil</description>
      <pubDate>Tue, 14 Jun 2005 15:36:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/4907295#M838295</guid>
      <dc:creator>RAC_1</dc:creator>
      <dc:date>2005-06-14T15:36:44Z</dc:date>
    </item>
    <item>
      <title>Re: script question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/4907296#M838296</link>
      <description>for SSN in `cat $WORKFILE | awk {'print $1'} |uniq`&lt;BR /&gt;do&lt;BR /&gt;grep $SSN $WORKFILE &amp;gt; /tmp/sometempfile&lt;BR /&gt;tot=0&lt;BR /&gt;cat /tmp/sometempfile|while read SSN HOURS&lt;BR /&gt;do&lt;BR /&gt;let tot=$tot+$HOURS&lt;BR /&gt;done&lt;BR /&gt;echo $SSN" has "$tot" total hours"&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;hope this helps&lt;BR /&gt;</description>
      <pubDate>Tue, 14 Jun 2005 15:37:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/4907296#M838296</guid>
      <dc:creator>Mel Burslan</dc:creator>
      <dc:date>2005-06-14T15:37:49Z</dc:date>
    </item>
    <item>
      <title>Re: script question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/4907297#M838297</link>
      <description>You don't bother to mention whether or not your first field is a string, integer, or floating point value nor do you bother to identify whether or not the values you are summing are simply integers. I'll assume the values to be summed are floating point; if not the fix is trivial. This is a good use of awk since you specified so little. Awk's arrays are associative which means that array["dog"] is just as valid as array[3].&lt;BR /&gt;&lt;BR /&gt;Create an awk script, my.awk :&lt;BR /&gt;{&lt;BR /&gt;  if ($1 in arry) arry[$1] += ($2 + 0)&lt;BR /&gt;  else arry[$1] = ($2 + 0)&lt;BR /&gt;}&lt;BR /&gt;END {&lt;BR /&gt;for (i in arry)&lt;BR /&gt;  {&lt;BR /&gt;    printf("%-20.20s %9.2f\n",i,arry[i])&lt;BR /&gt;  }&lt;BR /&gt;}&lt;BR /&gt;------------------------------------------&lt;BR /&gt;&lt;BR /&gt;Now invoke it like this:&lt;BR /&gt;awk -f my.awk &amp;lt; myinfile | sort&lt;BR /&gt;&lt;BR /&gt;I would create the awk script "on the fly" and include it in my shell script but this should get you started.&lt;BR /&gt;&lt;BR /&gt;If the values to be summed are integers, change the %9.2f to %9d and similarly, you might want to change the %-20.20s format to %09d if the sunscripts are integer or %09.2f if the subscripts are floating point values. The format of the subscript only matters in the sorting of the output.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 14 Jun 2005 15:45:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/4907297#M838297</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2005-06-14T15:45:32Z</dc:date>
    </item>
    <item>
      <title>Re: script question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/4907298#M838298</link>
      <description>Beautiful, Thanks for reading what I didn't write</description>
      <pubDate>Tue, 14 Jun 2005 16:04:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/4907298#M838298</guid>
      <dc:creator>Michael Treacy</dc:creator>
      <dc:date>2005-06-14T16:04:19Z</dc:date>
    </item>
    <item>
      <title>Re: script question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/4907299#M838299</link>
      <description>THANKS</description>
      <pubDate>Tue, 14 Jun 2005 16:06:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-question/m-p/4907299#M838299</guid>
      <dc:creator>Michael Treacy</dc:creator>
      <dc:date>2005-06-14T16:06:20Z</dc:date>
    </item>
  </channel>
</rss>

