<?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 bug or feature? in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-bug-or-feature/m-p/2828144#M721031</link>
    <description>Gord,&lt;BR /&gt;&lt;BR /&gt;Of course there is a patch for "awk".&lt;BR /&gt;&lt;BR /&gt;It's called "perl"  :-)&lt;BR /&gt;&lt;BR /&gt;-- Rod Hills</description>
    <pubDate>Thu, 17 Oct 2002 14:22:08 GMT</pubDate>
    <dc:creator>Rodney Hills</dc:creator>
    <dc:date>2002-10-17T14:22:08Z</dc:date>
    <item>
      <title>awk bug or feature?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-bug-or-feature/m-p/2828141#M721028</link>
      <description>I know squat about awk. A user sent me a note saying he thinks there is a bug that needs a patch.&lt;BR /&gt;&lt;BR /&gt;This is what he wrote. Hopefully I get the punctuation right.&lt;BR /&gt;&lt;BR /&gt;In the awk code:&lt;BR /&gt;   HOUR = substr($3,1,2)&lt;BR /&gt;   if (HOUR&amp;gt;=8 &amp;amp;&amp;amp; HOUR &amp;lt; 18) {&lt;BR /&gt;       ... code for prime shift&lt;BR /&gt;    }&lt;BR /&gt; The test was always failing, regardless of the assignment to HOUR. It looks like the problem is in the character to integer comparison. I corrected the script with a single line:&lt;BR /&gt;   HOUR = substr($3,1,2)&lt;BR /&gt;   HOUR = HOUR + 0&lt;BR /&gt;    if (HOUR ....&lt;BR /&gt;&lt;BR /&gt;He says that the script works and was wondering if there was a patch that I should throw on.&lt;BR /&gt;&lt;BR /&gt;What should I tell him? Is the script doing what it should? Is this a bug? Is there a better way to code it?&lt;BR /&gt;&lt;BR /&gt;Thanks.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 17 Oct 2002 14:00:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-bug-or-feature/m-p/2828141#M721028</guid>
      <dc:creator>Gord Moore</dc:creator>
      <dc:date>2002-10-17T14:00:05Z</dc:date>
    </item>
    <item>
      <title>Re: awk bug or feature?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-bug-or-feature/m-p/2828142#M721029</link>
      <description>substr returns a string and not a number which ends up foiling some of the "automatic" conversions that take place in awk.  This is not really a bug in awk, but a type of logic error in the script.  &lt;BR /&gt;&lt;BR /&gt;Your solution of adding "0" to the variable is fine, or you could use something like:&lt;BR /&gt;&lt;BR /&gt;HOUR = int(substr($3, 1, 2))&lt;BR /&gt;&lt;BR /&gt;instead which forces HOUR to be an integer.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;Rich</description>
      <pubDate>Thu, 17 Oct 2002 14:09:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-bug-or-feature/m-p/2828142#M721029</guid>
      <dc:creator>Richard Johnson_1</dc:creator>
      <dc:date>2002-10-17T14:09:49Z</dc:date>
    </item>
    <item>
      <title>Re: awk bug or feature?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-bug-or-feature/m-p/2828143#M721030</link>
      <description>Awk is working as it should. It is up to the programmer to force numeric context. Substr() is a string function. The 'trick' is to change&lt;BR /&gt;HOUR = substr($3,1,2)&lt;BR /&gt;to&lt;BR /&gt;HOUR = substr($3,1,2) + 0&lt;BR /&gt;&lt;BR /&gt;This will coerce HOUR into numeric context and all will then be well. Sometimes the reverse problem must be dealt with as well to force string context; the 'trick' in that case is to append a null string to a value. Both of these are stand awk idioms and well-disciplined awk programers will always use the '+ 0' to avoid those situations where one's code works (or doesn't work) by accident.&lt;BR /&gt;&lt;BR /&gt;If one doesn't force context, one will find cases where identical awk code will behave differently on different platforms.&lt;BR /&gt;</description>
      <pubDate>Thu, 17 Oct 2002 14:10:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-bug-or-feature/m-p/2828143#M721030</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2002-10-17T14:10:26Z</dc:date>
    </item>
    <item>
      <title>Re: awk bug or feature?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-bug-or-feature/m-p/2828144#M721031</link>
      <description>Gord,&lt;BR /&gt;&lt;BR /&gt;Of course there is a patch for "awk".&lt;BR /&gt;&lt;BR /&gt;It's called "perl"  :-)&lt;BR /&gt;&lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Thu, 17 Oct 2002 14:22:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-bug-or-feature/m-p/2828144#M721031</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2002-10-17T14:22:08Z</dc:date>
    </item>
  </channel>
</rss>

