<?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: How to group the output of a loop in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-group-the-output-of-a-loop/m-p/4459955#M680010</link>
    <description>----------------------&lt;BR /&gt;&lt;BR /&gt;emp_bk=`sqlplus -s scott/tiger....&amp;lt;&lt;EOF&gt;&lt;/EOF&gt;set pagesize ....&lt;BR /&gt;select e.emp_id||':'||sss_no from employee e, employee_bank eb&lt;BR /&gt;where e.emp_id=eb.emp_id;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;output :&lt;BR /&gt;4567:45566&lt;BR /&gt;2231:59589&lt;BR /&gt;1121:55170&lt;BR /&gt;2233:51530&lt;BR /&gt;....&lt;BR /&gt;&lt;BR /&gt;#&lt;BR /&gt;# count lines&lt;BR /&gt;if test `echo $emp_bk|wc -l` -lt 7&lt;BR /&gt;   then echo "one group only"&lt;BR /&gt;        multigroup=no&lt;BR /&gt;   else echo "multiple groups"&lt;BR /&gt;        multigroup=yes&lt;BR /&gt;fi&lt;BR /&gt;#&lt;BR /&gt;# set group number to 1&lt;BR /&gt;group_no=1&lt;BR /&gt;cnt=1&lt;BR /&gt;for x in $emp_bk&lt;BR /&gt;do&lt;BR /&gt;#&lt;BR /&gt;# get employee number, bank number&lt;BR /&gt;  emp_no=`echo $x|cut -d':' -f1`&lt;BR /&gt;  bank_no=`echo $x|cut -d':' -f2`&lt;BR /&gt;        &lt;BR /&gt;#assemble group name 'GROUP' and actual group number&lt;BR /&gt;  w_grp="GROUP"$group&lt;BR /&gt;#&lt;BR /&gt;# execute ss_move&lt;BR /&gt;  sss_move $bank_no $w_grp&lt;BR /&gt;&lt;BR /&gt;# &lt;BR /&gt;# add 1 to counter. if &amp;gt; 2 then add 1 to group counter&lt;BR /&gt;# set counter to 1&lt;BR /&gt;  cnt=$cnt+1&lt;BR /&gt;  if test $cnt -eq 3&lt;BR /&gt;     then cnt=1&lt;BR /&gt;          group_no=$group_no+1&lt;BR /&gt;  fi&lt;BR /&gt;#&lt;BR /&gt;# reset group counter to 1 in case we just have one group&lt;BR /&gt;  if test "$multigroup" = "no"&lt;BR /&gt;     then group_no=1&lt;BR /&gt;  fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;--------------------------------------------&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;comment&lt;BR /&gt;cnt=$cnt+1 : you need to use expr to increase the number by 1.</description>
    <pubDate>Wed, 15 Jul 2009 07:15:36 GMT</pubDate>
    <dc:creator>SSCHAER</dc:creator>
    <dc:date>2009-07-15T07:15:36Z</dc:date>
    <item>
      <title>How to group the output of a loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-group-the-output-of-a-loop/m-p/4459954#M680009</link>
      <description>Hi Guys,&lt;BR /&gt;&lt;BR /&gt;First time user &amp;amp; new to scripting. :) &lt;BR /&gt;&lt;BR /&gt;I have my shell script like this:&lt;BR /&gt;&lt;BR /&gt;[CODE]&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;e_id=`sqlplus -s scott/tiger@DB&amp;lt;&lt;EOF&gt;&lt;/EOF&gt;            SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF;&lt;BR /&gt;            select emp_id from employee;&lt;BR /&gt;            quit&lt;BR /&gt;            `&lt;BR /&gt;echo "Employee ID's $e_id"&lt;BR /&gt;&lt;BR /&gt;group=GROUP1&lt;BR /&gt;# Getting the sss_no for each emp_id&lt;BR /&gt;&lt;BR /&gt;for i in $e_id &lt;BR /&gt; do&lt;BR /&gt;   sss_nos=`sqlplus -s scott/tiger@DB &amp;lt;&lt;EOF&gt;&lt;/EOF&gt;          SET PAGES 0 LINES 500 HEAD OFF;&lt;BR /&gt;          select sss_no from employee_bank where emp_id = $i;&lt;BR /&gt;          quit&lt;BR /&gt;          `&lt;BR /&gt;   echo "List of SSS no's $sss_nos"&lt;BR /&gt;   # Run a customize program that calls the sss_nos&lt;BR /&gt;   # SSS_move&lt;BR /&gt;   SSS_move $sss_nos $group&lt;BR /&gt;  sleep 2&lt;BR /&gt;done&lt;BR /&gt;[/CODE]&lt;BR /&gt;&lt;BR /&gt;The Output:&lt;BR /&gt;Employee ID's &lt;BR /&gt;4567&lt;BR /&gt;2231&lt;BR /&gt;1121&lt;BR /&gt;2233&lt;BR /&gt;4554&lt;BR /&gt;3243&lt;BR /&gt;1231&lt;BR /&gt;3311&lt;BR /&gt;&lt;BR /&gt;List of SSS no's&lt;BR /&gt;45566&lt;BR /&gt;59589&lt;BR /&gt;55170&lt;BR /&gt;51530&lt;BR /&gt;33099&lt;BR /&gt;20234&lt;BR /&gt;87231&lt;BR /&gt;54192&lt;BR /&gt;&lt;BR /&gt;SSS_move:&lt;BR /&gt;SSS_move 45566 GROUP1&lt;BR /&gt;SSS_move 59589 GROUP1&lt;BR /&gt;SSS_move 55170 GROUP1&lt;BR /&gt;SSS_move 51530 GROUP1&lt;BR /&gt;SSS_move 33099 GROUP1&lt;BR /&gt;SSS_move 20234 GROUP1&lt;BR /&gt;SSS_move 87231 GROUP1&lt;BR /&gt;SSS_move 54192 GROUP1&lt;BR /&gt;&lt;BR /&gt;Now, how will I able to group the output of the loop so that I can assign GROUP1 only to the 1st two output of the loop then assign GROUP2 to the 2nd two output of the loop &amp;amp; so on. :confused: &lt;BR /&gt;&lt;BR /&gt;Desired Output:&lt;BR /&gt;SSS_move 45566 GROUP1&lt;BR /&gt;SSS_move 59589 GROUP1&lt;BR /&gt;SSS_move 55170 GROUP2&lt;BR /&gt;SSS_move 51530 GROUP2&lt;BR /&gt;SSS_move 33099 GROUP3&lt;BR /&gt;SSS_move 20234 GROUP3&lt;BR /&gt;SSS_move 87231 GROUP4&lt;BR /&gt;SSS_move 54192 GROUP4&lt;BR /&gt;&lt;BR /&gt;Also, how do I count the $sss_nos output so that I have this condition:&lt;BR /&gt;If my $sss_nos -gt 7 (w/c in my example above it is true) then assign to multiple GROUP#. If it is -lt 7 then group it only to GROUP1&lt;BR /&gt;&lt;BR /&gt;Pls. help :D &lt;BR /&gt;&lt;BR /&gt;Thanx in advance :)</description>
      <pubDate>Wed, 15 Jul 2009 06:35:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-group-the-output-of-a-loop/m-p/4459954#M680009</guid>
      <dc:creator>Alvin Ramos</dc:creator>
      <dc:date>2009-07-15T06:35:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to group the output of a loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-group-the-output-of-a-loop/m-p/4459955#M680010</link>
      <description>----------------------&lt;BR /&gt;&lt;BR /&gt;emp_bk=`sqlplus -s scott/tiger....&amp;lt;&lt;EOF&gt;&lt;/EOF&gt;set pagesize ....&lt;BR /&gt;select e.emp_id||':'||sss_no from employee e, employee_bank eb&lt;BR /&gt;where e.emp_id=eb.emp_id;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;output :&lt;BR /&gt;4567:45566&lt;BR /&gt;2231:59589&lt;BR /&gt;1121:55170&lt;BR /&gt;2233:51530&lt;BR /&gt;....&lt;BR /&gt;&lt;BR /&gt;#&lt;BR /&gt;# count lines&lt;BR /&gt;if test `echo $emp_bk|wc -l` -lt 7&lt;BR /&gt;   then echo "one group only"&lt;BR /&gt;        multigroup=no&lt;BR /&gt;   else echo "multiple groups"&lt;BR /&gt;        multigroup=yes&lt;BR /&gt;fi&lt;BR /&gt;#&lt;BR /&gt;# set group number to 1&lt;BR /&gt;group_no=1&lt;BR /&gt;cnt=1&lt;BR /&gt;for x in $emp_bk&lt;BR /&gt;do&lt;BR /&gt;#&lt;BR /&gt;# get employee number, bank number&lt;BR /&gt;  emp_no=`echo $x|cut -d':' -f1`&lt;BR /&gt;  bank_no=`echo $x|cut -d':' -f2`&lt;BR /&gt;        &lt;BR /&gt;#assemble group name 'GROUP' and actual group number&lt;BR /&gt;  w_grp="GROUP"$group&lt;BR /&gt;#&lt;BR /&gt;# execute ss_move&lt;BR /&gt;  sss_move $bank_no $w_grp&lt;BR /&gt;&lt;BR /&gt;# &lt;BR /&gt;# add 1 to counter. if &amp;gt; 2 then add 1 to group counter&lt;BR /&gt;# set counter to 1&lt;BR /&gt;  cnt=$cnt+1&lt;BR /&gt;  if test $cnt -eq 3&lt;BR /&gt;     then cnt=1&lt;BR /&gt;          group_no=$group_no+1&lt;BR /&gt;  fi&lt;BR /&gt;#&lt;BR /&gt;# reset group counter to 1 in case we just have one group&lt;BR /&gt;  if test "$multigroup" = "no"&lt;BR /&gt;     then group_no=1&lt;BR /&gt;  fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;--------------------------------------------&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;comment&lt;BR /&gt;cnt=$cnt+1 : you need to use expr to increase the number by 1.</description>
      <pubDate>Wed, 15 Jul 2009 07:15:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-group-the-output-of-a-loop/m-p/4459955#M680010</guid>
      <dc:creator>SSCHAER</dc:creator>
      <dc:date>2009-07-15T07:15:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to group the output of a loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-group-the-output-of-a-loop/m-p/4459956#M680011</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; cnt=$cnt+1 : you need to use expr to increase the number by 1.&lt;BR /&gt;&lt;BR /&gt;Using 'expr' is slow.  Let the shell do the arithmetic:&lt;BR /&gt;&lt;BR /&gt;# cnt=$(($cnt+1))&lt;BR /&gt;&lt;BR /&gt;For example:&lt;BR /&gt;&lt;BR /&gt;# cnt=1;cnt=$(($cnt+1));echo ${cnt}&lt;BR /&gt;2&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Wed, 15 Jul 2009 10:48:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-group-the-output-of-a-loop/m-p/4459956#M680011</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-07-15T10:48:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to group the output of a loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-group-the-output-of-a-loop/m-p/4459957#M680012</link>
      <description>&amp;gt;JRF: Let the shell do the arithmetic: cnt=$(($cnt+1))&lt;BR /&gt;&lt;BR /&gt;Or even better: (( cnt += 1 ))</description>
      <pubDate>Wed, 15 Jul 2009 11:59:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-group-the-output-of-a-loop/m-p/4459957#M680012</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-07-15T11:59:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to group the output of a loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-group-the-output-of-a-loop/m-p/4459958#M680013</link>
      <description>@sschaer, thanx - this gives me an idea.&lt;BR /&gt;&lt;BR /&gt;@JRF, thanx&lt;BR /&gt;&lt;BR /&gt;@Dennis Handly, &lt;BR /&gt;what does ((cnt += 1)) means (increment then equals to)????&lt;BR /&gt;&lt;BR /&gt;Thanx Guys</description>
      <pubDate>Wed, 15 Jul 2009 23:52:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-group-the-output-of-a-loop/m-p/4459958#M680013</guid>
      <dc:creator>Alvin Ramos</dc:creator>
      <dc:date>2009-07-15T23:52:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to group the output of a loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-group-the-output-of-a-loop/m-p/4459959#M680014</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; cnt=$(($cnt+1))&lt;BR /&gt;&lt;BR /&gt;&amp;gt; (( cnt += 1 ))&lt;BR /&gt;&lt;BR /&gt;These are equivalent operations.  The second simply means increment the variable by one and destructively store the new value into the variable.  The second form is shorthand for the first form.  The first form would be used if you wanted to increment by a value other than one, as for example:&lt;BR /&gt;&lt;BR /&gt;cnt=$(($cnt+2))&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 16 Jul 2009 00:02:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-group-the-output-of-a-loop/m-p/4459959#M680014</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-07-16T00:02:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to group the output of a loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-group-the-output-of-a-loop/m-p/4459960#M680015</link>
      <description>&amp;gt;JRF: The first form would be used if you wanted to increment by a value other than one, as for example: cnt=$(($cnt+2))&lt;BR /&gt;&lt;BR /&gt;Perhaps you are confusing the operator ++ with +=.  Note the scummy real shell doesn't support ++/--.&lt;BR /&gt;To increment by 2: (( cnt += 2 ))&lt;BR /&gt;Basically there isn't a need to use the first form if you are doing integer arithmetic.</description>
      <pubDate>Thu, 16 Jul 2009 10:51:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-group-the-output-of-a-loop/m-p/4459960#M680015</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-07-16T10:51:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to group the output of a loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-group-the-output-of-a-loop/m-p/4459961#M680016</link>
      <description>&amp;gt;what does ((cnt += 1)) means (increment then equals to)?&lt;BR /&gt;&lt;BR /&gt;More specifically, in C/C++ a compound assignment is the same as:&lt;BR /&gt;L O= R  ==&amp;gt;  L = L O R&lt;BR /&gt;Where O is any of the binary operators.</description>
      <pubDate>Thu, 16 Jul 2009 10:54:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-group-the-output-of-a-loop/m-p/4459961#M680016</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-07-16T10:54:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to group the output of a loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-group-the-output-of-a-loop/m-p/4459962#M680017</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;&amp;gt; Dennis: Perhaps you are confusing the operator ++ with +=. Note the scummy real shell doesn't support ++/--.&lt;BR /&gt;&lt;BR /&gt;Yes, indeed I was!  I know that ++/-- aren't supported by the shell (a damn shame!) but I confess I wasn't aware that one could do '(( cnt += 2 ))'.&lt;BR /&gt;&lt;BR /&gt;Dennis, thanks for the clarification!&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Thu, 16 Jul 2009 11:02:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-group-the-output-of-a-loop/m-p/4459962#M680017</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-07-16T11:02:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to group the output of a loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-group-the-output-of-a-loop/m-p/4459963#M680018</link>
      <description>&amp;gt;JRF: I confess I wasn't aware that one could do '(( cnt += 2 ))'.&lt;BR /&gt;&lt;BR /&gt;You can also do: (( cnt = aaa + bbb ))&lt;BR /&gt;</description>
      <pubDate>Thu, 16 Jul 2009 11:16:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-group-the-output-of-a-loop/m-p/4459963#M680018</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-07-16T11:16:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to group the output of a loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/how-to-group-the-output-of-a-loop/m-p/4459964#M680019</link>
      <description>&lt;!--!*#--&gt;To get the output to 1 "group" I would recommend doing it as a function.&lt;BR /&gt;&lt;BR /&gt;This way you can execute the function within a variable and then you have a grouped output.&lt;BR /&gt;&lt;BR /&gt;Something like this might be the key.&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;function do_dragon {&lt;BR /&gt; e_id=$(sqlplus -s scott/tiger@DB&amp;lt;&lt;EOF&gt;&lt;/EOF&gt;  SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF;&lt;BR /&gt;  select emp_id from employee;&lt;BR /&gt;  quit&lt;BR /&gt; )&lt;BR /&gt;&lt;BR /&gt; group=GROUP1&lt;BR /&gt; # Getting the sss_no for each emp_id&lt;BR /&gt;&lt;BR /&gt; for i in $e_id; do&lt;BR /&gt;  sss_nos=$(sqlplus -s scott/tiger@DB &amp;lt;&lt;EOF&gt;&lt;/EOF&gt;   SET PAGES 0 LINES 500 HEAD OFF;&lt;BR /&gt;   select sss_no from employee_bank where emp_id = $i;&lt;BR /&gt;   quit&lt;BR /&gt;  )&lt;BR /&gt;&lt;BR /&gt;  echo "List of SSS no's $sss_nos"&lt;BR /&gt;  # Run a customize program that calls the sss_nos&lt;BR /&gt;  # SSS_move&lt;BR /&gt;  SSS_move $sss_nos $group&lt;BR /&gt;  sleep 2&lt;BR /&gt; done&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;echo "Employee ID's $e_id"&lt;BR /&gt;&lt;BR /&gt;output=$(do_dragon)&lt;BR /&gt;echo $output&lt;BR /&gt;&lt;BR /&gt;ps. haven't tested it :P so might need some tweaking ds.&lt;BR /&gt;&lt;BR /&gt;Best regards&lt;BR /&gt;Fredrik Eriksson&lt;BR /&gt;</description>
      <pubDate>Thu, 16 Jul 2009 13:06:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/how-to-group-the-output-of-a-loop/m-p/4459964#M680019</guid>
      <dc:creator>Fredrik.eriksson</dc:creator>
      <dc:date>2009-07-16T13:06:52Z</dc:date>
    </item>
  </channel>
</rss>

