<?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: Using substr() to get a value for a loop in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-using-substr-to-get-a-value-for-a-loop/m-p/2658146#M722935</link>
    <description>Hello Clay,&lt;BR /&gt;&lt;BR /&gt;Thanks, that worked a treat! (I posted my previous reply before I read yours).&lt;BR /&gt;&lt;BR /&gt;Although I could work round this I was more curious to work out whether I was doing it right or not.&lt;BR /&gt;&lt;BR /&gt;Thanks again,&lt;BR /&gt;&lt;BR /&gt;Simon.</description>
    <pubDate>Mon, 04 Feb 2002 14:37:02 GMT</pubDate>
    <dc:creator>Simon Abbott</dc:creator>
    <dc:date>2002-02-04T14:37:02Z</dc:date>
    <item>
      <title>awk: Using substr() to get a value for a loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-using-substr-to-get-a-value-for-a-loop/m-p/2658139#M722928</link>
      <description>Hello everyone,&lt;BR /&gt;&lt;BR /&gt;I am using substr() to get a value from the second to the last character of a string (see code below). for example, I want 321 from A321. I then want to run through a loop that many times.&lt;BR /&gt;&lt;BR /&gt;I ran this happily for months until we moved to another server last week and (I'm guessing) a later version of awk. Now, the for loop only runs the number of times of the first character of the value, so if the value is 321 it runs only 3 times, it it's 421 it runs 4 times. I get the expected result out of an if statement but not a for statement.&lt;BR /&gt;&lt;BR /&gt;If I use split(), everything works fine but substr() doesn't. Is this a bug, and if so is it a bug in the newer version or was I taking advantage of a bug in the old version? If it is a bug in the newer version is there a fix? I it is a bug in the old version is there a better way of extracting this value, other then using split() like this: simon=value[split($1,value,"A")]&lt;BR /&gt;&lt;BR /&gt;Cheers, Simon.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;the file awk is processing has one line:&lt;BR /&gt;A321&lt;BR /&gt;&lt;BR /&gt;the output I get is:&lt;BR /&gt;1&lt;BR /&gt;2&lt;BR /&gt;3&lt;BR /&gt;&lt;BR /&gt;---&lt;BR /&gt;&lt;BR /&gt;{&lt;BR /&gt;   simon  = substr($1,2)&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;END {&lt;BR /&gt;&lt;BR /&gt;   for ( i = 1 ; i &amp;lt;= simon ; i++ )&lt;BR /&gt;   {&lt;BR /&gt;      print 1&lt;BR /&gt;   }&lt;BR /&gt;}</description>
      <pubDate>Mon, 04 Feb 2002 14:12:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-using-substr-to-get-a-value-for-a-loop/m-p/2658139#M722928</guid>
      <dc:creator>Simon Abbott</dc:creator>
      <dc:date>2002-02-04T14:12:03Z</dc:date>
    </item>
    <item>
      <title>Re: awk: Using substr() to get a value for a loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-using-substr-to-get-a-value-for-a-loop/m-p/2658140#M722929</link>
      <description>That last bit should read print i, not print 1&lt;BR /&gt;&lt;BR /&gt;Simon.</description>
      <pubDate>Mon, 04 Feb 2002 14:16:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-using-substr-to-get-a-value-for-a-loop/m-p/2658140#M722929</guid>
      <dc:creator>Simon Abbott</dc:creator>
      <dc:date>2002-02-04T14:16:36Z</dc:date>
    </item>
    <item>
      <title>Re: awk: Using substr() to get a value for a loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-using-substr-to-get-a-value-for-a-loop/m-p/2658141#M722930</link>
      <description>why not use sed to trim out the alphabetics and load into a separate variable?&lt;BR /&gt;&lt;BR /&gt;export NUMBER=`echo $SIMON | sed 's/[A-Za-z]//g'`&lt;BR /&gt;&lt;BR /&gt;Share and Enjoy! Ian</description>
      <pubDate>Mon, 04 Feb 2002 14:17:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-using-substr-to-get-a-value-for-a-loop/m-p/2658141#M722930</guid>
      <dc:creator>ian Dennison</dc:creator>
      <dc:date>2002-02-04T14:17:37Z</dc:date>
    </item>
    <item>
      <title>Re: awk: Using substr() to get a value for a loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-using-substr-to-get-a-value-for-a-loop/m-p/2658142#M722931</link>
      <description>Cheers Ian,&lt;BR /&gt;&lt;BR /&gt;Unfortunatly however, that file that awk processes is the output of an executable and the awk script does alot more - I've just simplified it here.&lt;BR /&gt;&lt;BR /&gt;Simon.</description>
      <pubDate>Mon, 04 Feb 2002 14:21:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-using-substr-to-get-a-value-for-a-loop/m-p/2658142#M722931</guid>
      <dc:creator>Simon Abbott</dc:creator>
      <dc:date>2002-02-04T14:21:56Z</dc:date>
    </item>
    <item>
      <title>Re: awk: Using substr() to get a value for a loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-using-substr-to-get-a-value-for-a-loop/m-p/2658143#M722932</link>
      <description>Try replacing substr with&lt;BR /&gt;  substr($1,2,999)&lt;BR /&gt;&lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Mon, 04 Feb 2002 14:24:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-using-substr-to-get-a-value-for-a-loop/m-p/2658143#M722932</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2002-02-04T14:24:09Z</dc:date>
    </item>
    <item>
      <title>Re: awk: Using substr() to get a value for a loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-using-substr-to-get-a-value-for-a-loop/m-p/2658144#M722933</link>
      <description>Hi Simon:&lt;BR /&gt;&lt;BR /&gt;You need to coerce the value returned by substr to be numeric rather than string. This is a pretty standard awk idiom:&lt;BR /&gt;&lt;BR /&gt;simon = substr($1,2) + 0&lt;BR /&gt;&lt;BR /&gt;The '+ 0' should do the trick for you. You old version was actually working by accident. Remember arrays in awk are associative so that what you you of an numerical indices really aren't. Perl neatly bushwhacks this by having both array (numeric indices) and hashes (associative indices).&lt;BR /&gt;&lt;BR /&gt;Regards, Clay &lt;BR /&gt;</description>
      <pubDate>Mon, 04 Feb 2002 14:25:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-using-substr-to-get-a-value-for-a-loop/m-p/2658144#M722933</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2002-02-04T14:25:42Z</dc:date>
    </item>
    <item>
      <title>Re: awk: Using substr() to get a value for a loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-using-substr-to-get-a-value-for-a-loop/m-p/2658145#M722934</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;I tried that but it still doesn't like it. It is taking 321 as a value of some kind because&lt;BR /&gt;&lt;BR /&gt;if ( simon == 321 ) print "hello"&lt;BR /&gt;&lt;BR /&gt;works. I wondered whether it thinks 321 is a string and not an integer?&lt;BR /&gt;&lt;BR /&gt;Simon.</description>
      <pubDate>Mon, 04 Feb 2002 14:28:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-using-substr-to-get-a-value-for-a-loop/m-p/2658145#M722934</guid>
      <dc:creator>Simon Abbott</dc:creator>
      <dc:date>2002-02-04T14:28:01Z</dc:date>
    </item>
    <item>
      <title>Re: awk: Using substr() to get a value for a loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-using-substr-to-get-a-value-for-a-loop/m-p/2658146#M722935</link>
      <description>Hello Clay,&lt;BR /&gt;&lt;BR /&gt;Thanks, that worked a treat! (I posted my previous reply before I read yours).&lt;BR /&gt;&lt;BR /&gt;Although I could work round this I was more curious to work out whether I was doing it right or not.&lt;BR /&gt;&lt;BR /&gt;Thanks again,&lt;BR /&gt;&lt;BR /&gt;Simon.</description>
      <pubDate>Mon, 04 Feb 2002 14:37:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-using-substr-to-get-a-value-for-a-loop/m-p/2658146#M722935</guid>
      <dc:creator>Simon Abbott</dc:creator>
      <dc:date>2002-02-04T14:37:02Z</dc:date>
    </item>
    <item>
      <title>Re: awk: Using substr() to get a value for a loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-using-substr-to-get-a-value-for-a-loop/m-p/2658147#M722936</link>
      <description>Hi Simon:&lt;BR /&gt;&lt;BR /&gt;What are your awk versions (from the output of 'what /usr/bin/awk')?&lt;BR /&gt;&lt;BR /&gt;On a 10.20 server I have:&lt;BR /&gt;&lt;BR /&gt;$Revision: 78.14.1.12 $&lt;BR /&gt;         PATCH_10_20: awk.g.o awk.lx.o b.o main.o tran.o lib.o run.o parse.o pro&lt;BR /&gt;ctab.o hpux_rel.o 99/05/06&lt;BR /&gt;&lt;BR /&gt;On an 11.0 server I see:&lt;BR /&gt;&lt;BR /&gt;#Revision: 82.2 $&lt;BR /&gt;&lt;BR /&gt;In both cases I get an expected 12-lines of output from this test case:&lt;BR /&gt;&lt;BR /&gt;# echo "A12"|awk '{X=substr($1,2)};END {for (i=1;i&amp;lt;=X;i++) {print i}}'&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 04 Feb 2002 14:38:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-using-substr-to-get-a-value-for-a-loop/m-p/2658147#M722936</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2002-02-04T14:38:44Z</dc:date>
    </item>
    <item>
      <title>Re: awk: Using substr() to get a value for a loop</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-using-substr-to-get-a-value-for-a-loop/m-p/2658148#M722937</link>
      <description>Hello James,&lt;BR /&gt;&lt;BR /&gt;Mine is 78.14.1.16 (the old one was 78.14.1.1) so I guess that's why.&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;&lt;BR /&gt;Simon.</description>
      <pubDate>Mon, 04 Feb 2002 14:45:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-using-substr-to-get-a-value-for-a-loop/m-p/2658148#M722937</guid>
      <dc:creator>Simon Abbott</dc:creator>
      <dc:date>2002-02-04T14:45:32Z</dc:date>
    </item>
  </channel>
</rss>

