<?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: loop in script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/loop-in-script/m-p/2778340#M722471</link>
    <description>Sharil,&lt;BR /&gt;&lt;BR /&gt;you reference your array incorrectly,&lt;BR /&gt;it should be like this&lt;BR /&gt;&lt;BR /&gt;for file in ${MONFILE[*]}; do&lt;BR /&gt;# do something with $file&lt;BR /&gt;done</description>
    <pubDate>Fri, 02 Aug 2002 08:57:04 GMT</pubDate>
    <dc:creator>Ralph Grothe</dc:creator>
    <dc:date>2002-08-02T08:57:04Z</dc:date>
    <item>
      <title>loop in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/loop-in-script/m-p/2778337#M722468</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;Appreciate help what's wrong w/ the set syntax:&lt;BR /&gt;&lt;BR /&gt;set -A MONFILE "/tmp/RC1.log" "/tmp/RC2.log"&lt;BR /&gt;count=0&lt;BR /&gt;for i in $MONFILE&lt;BR /&gt;do&lt;BR /&gt;ERR=`tail -1 $i|grep ^ERR|wc -l`&lt;BR /&gt;count=`expr $ERR + $count`&lt;BR /&gt;echo $i&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Rgds,&lt;BR /&gt;Shahril&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;P.S. This thread has been moved from HP-UX &amp;gt;&amp;nbsp;General to HP-UX &amp;gt; languages - HP Forums Moderator&lt;/P&gt;</description>
      <pubDate>Mon, 22 Oct 2012 07:14:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/loop-in-script/m-p/2778337#M722468</guid>
      <dc:creator>Shahril M</dc:creator>
      <dc:date>2012-10-22T07:14:10Z</dc:date>
    </item>
    <item>
      <title>Re: loop in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/loop-in-script/m-p/2778338#M722469</link>
      <description>your set -A doesnt work. Change your script to;&lt;BR /&gt;&lt;BR /&gt;count=0&lt;BR /&gt;for i in "/tmp/RC1.log" "/tmp/RC2.log"&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;and expr doesnt work if not ^ERR found so change it to;&lt;BR /&gt;let count=$count+$ERR&lt;BR /&gt;&lt;BR /&gt;and it works fine.&lt;BR /&gt;</description>
      <pubDate>Fri, 02 Aug 2002 08:12:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/loop-in-script/m-p/2778338#M722469</guid>
      <dc:creator>Stefan Farrelly</dc:creator>
      <dc:date>2002-08-02T08:12:32Z</dc:date>
    </item>
    <item>
      <title>Re: loop in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/loop-in-script/m-p/2778339#M722470</link>
      <description>Hi Shahril,&lt;BR /&gt;&lt;BR /&gt;Try with this:&lt;BR /&gt;set -A MONFILE "/tmp/RC1.log" "/tmp/RC2.log" &lt;BR /&gt;count=0 &lt;BR /&gt;for i in $MONFILE &lt;BR /&gt;do &lt;BR /&gt;ERR=`tail -1 $i|grep "^ERR" |wc -l` &lt;BR /&gt;if [ $ERR -gt 0 ]&lt;BR /&gt;then&lt;BR /&gt;(( count = $ERR + $count ))&lt;BR /&gt;fi &lt;BR /&gt;echo $i &lt;BR /&gt;done &lt;BR /&gt;&lt;BR /&gt;Hope this help you,&lt;BR /&gt;&lt;BR /&gt;Justo.</description>
      <pubDate>Fri, 02 Aug 2002 08:47:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/loop-in-script/m-p/2778339#M722470</guid>
      <dc:creator>Justo Exposito</dc:creator>
      <dc:date>2002-08-02T08:47:09Z</dc:date>
    </item>
    <item>
      <title>Re: loop in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/loop-in-script/m-p/2778340#M722471</link>
      <description>Sharil,&lt;BR /&gt;&lt;BR /&gt;you reference your array incorrectly,&lt;BR /&gt;it should be like this&lt;BR /&gt;&lt;BR /&gt;for file in ${MONFILE[*]}; do&lt;BR /&gt;# do something with $file&lt;BR /&gt;done</description>
      <pubDate>Fri, 02 Aug 2002 08:57:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/loop-in-script/m-p/2778340#M722471</guid>
      <dc:creator>Ralph Grothe</dc:creator>
      <dc:date>2002-08-02T08:57:04Z</dc:date>
    </item>
    <item>
      <title>Re: loop in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/loop-in-script/m-p/2778341#M722472</link>
      <description>Addendum,&lt;BR /&gt;if you really insist on indexing (which is kind of daft) you could do something like this (remember  ${#MONFILE} gives the dimsion of your array)&lt;BR /&gt;&lt;BR /&gt;typeset -i i=0&lt;BR /&gt;while [ i -lt ${#MONFILE[*] ]; do&lt;BR /&gt;file=${MONFILE[i]}&lt;BR /&gt;((i+=1))&lt;BR /&gt;done</description>
      <pubDate>Fri, 02 Aug 2002 09:01:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/loop-in-script/m-p/2778341#M722472</guid>
      <dc:creator>Ralph Grothe</dc:creator>
      <dc:date>2002-08-02T09:01:18Z</dc:date>
    </item>
    <item>
      <title>Re: loop in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/loop-in-script/m-p/2778342#M722473</link>
      <description>Oops typo,&lt;BR /&gt;&lt;BR /&gt;the dimension of the array is of course&lt;BR /&gt;${#MONFILE[*]}&lt;BR /&gt;&lt;BR /&gt;whereas&lt;BR /&gt;&lt;BR /&gt;${#MONFILE}&lt;BR /&gt;&lt;BR /&gt;only gives the length of the string of the 1st element&lt;BR /&gt;(but I guess you realized my typo ;-)</description>
      <pubDate>Fri, 02 Aug 2002 09:04:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/loop-in-script/m-p/2778342#M722473</guid>
      <dc:creator>Ralph Grothe</dc:creator>
      <dc:date>2002-08-02T09:04:38Z</dc:date>
    </item>
    <item>
      <title>Re: loop in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/loop-in-script/m-p/2778343#M722474</link>
      <description>Ouch another typo crept in,&lt;BR /&gt;in the test condition of the while loop you have to prepend a dollar sign to the integer variable i,&lt;BR /&gt;(e.g. while [ $i -lt ...)&lt;BR /&gt;or use the [[ ]] test operator syntax</description>
      <pubDate>Fri, 02 Aug 2002 09:11:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/loop-in-script/m-p/2778343#M722474</guid>
      <dc:creator>Ralph Grothe</dc:creator>
      <dc:date>2002-08-02T09:11:18Z</dc:date>
    </item>
    <item>
      <title>Re: loop in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/loop-in-script/m-p/2778344#M722475</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;If you just want to count the number of error lines in 2 files&lt;BR /&gt;&lt;BR /&gt;typeset -i count=$(grep ^ERR /tmp/RC1.log /tmp/RC2.log)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Steve Steel</description>
      <pubDate>Fri, 02 Aug 2002 09:19:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/loop-in-script/m-p/2778344#M722475</guid>
      <dc:creator>Steve Steel</dc:creator>
      <dc:date>2002-08-02T09:19:42Z</dc:date>
    </item>
    <item>
      <title>Re: loop in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/loop-in-script/m-p/2778345#M722476</link>
      <description>I think everyone answered this already to some good degree, but I'll add my 8 points worth.&lt;BR /&gt;&lt;BR /&gt;set -A MONFILE "/tmp/RC1.log" "/tmp/RC2.log"&lt;BR /&gt;typeset -i count=0 ERR=0&lt;BR /&gt;for i in ${MONFILE[@]}&lt;BR /&gt;do&lt;BR /&gt;ERR=$(tail -1 $i | grep ^ERR | wc -l)&lt;BR /&gt;let count+=$ERR&lt;BR /&gt;echo $i&lt;BR /&gt;done&lt;BR /&gt;echo $count&lt;BR /&gt;&lt;BR /&gt;To use all the elements of the array, the array name must be suffixed with [@] or [*] and wrapped in {}.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;You could even do it this way:&lt;BR /&gt;&lt;BR /&gt;typeset -i count=0&lt;BR /&gt;set -A MONFILE "/tmp/RC1.log" "/tmp/RC2.log"&lt;BR /&gt;for i in ${MONFILE[@]}&lt;BR /&gt;do&lt;BR /&gt;tail -1 $i&lt;BR /&gt;done | grep ^ERR | wc -l | read count&lt;BR /&gt;echo $count&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 02 Aug 2002 20:22:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/loop-in-script/m-p/2778345#M722476</guid>
      <dc:creator>Jordan Bean</dc:creator>
      <dc:date>2002-08-02T20:22:11Z</dc:date>
    </item>
    <item>
      <title>Re: loop in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/loop-in-script/m-p/2778346#M722477</link>
      <description>Shahril:&lt;BR /&gt;&lt;BR /&gt;I have to agree that using an array is more trouble than it is worth in this case.  I would use filename generation:&lt;BR /&gt;&lt;BR /&gt;count=0&lt;BR /&gt;for I in /tmp/RC?.log&lt;BR /&gt;do&lt;BR /&gt;    ERR=$(tail -1 $I | grep -c ^ERR)&lt;BR /&gt;    ((count += ERR))&lt;BR /&gt;    print $I&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;The code following "in" should interpret to a list.  /tmp/RC?.log returns all files that match (e.g. RC1.log, RCa.log, RCA.log).  If you want to restrict to numbers, use /tmp/RC[0-9].log&lt;BR /&gt;&lt;BR /&gt;-dlt-&lt;BR /&gt;</description>
      <pubDate>Sun, 04 Aug 2002 01:07:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/loop-in-script/m-p/2778346#M722477</guid>
      <dc:creator>David Totsch</dc:creator>
      <dc:date>2002-08-04T01:07:33Z</dc:date>
    </item>
    <item>
      <title>Re: loop in script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/loop-in-script/m-p/2778347#M722478</link>
      <description>I now learn that "set -A" constitutes to defining an array,&lt;BR /&gt;but under what circumstances is it necessary to subscript it to reference the elements?&lt;BR /&gt;I ask because I have seen instances of "for i in $HOST" and the like.&lt;BR /&gt;&lt;BR /&gt;I used "set -A" because I need to reference the filenames again later in the script.&lt;BR /&gt;&lt;BR /&gt;Thanx to those who have helped and taught me.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Rgds,&lt;BR /&gt;Shahril&lt;BR /&gt;</description>
      <pubDate>Mon, 05 Aug 2002 07:53:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/loop-in-script/m-p/2778347#M722478</guid>
      <dc:creator>Shahril M</dc:creator>
      <dc:date>2002-08-05T07:53:41Z</dc:date>
    </item>
  </channel>
</rss>

