<?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: range check in awk in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/range-check-in-awk/m-p/2630414#M921176</link>
    <description>Make sure when you use FS you are using FS="[-,]" so you get ranges and individual integers.</description>
    <pubDate>Wed, 12 Dec 2001 17:39:46 GMT</pubDate>
    <dc:creator>Jeff Machols</dc:creator>
    <dc:date>2001-12-12T17:39:46Z</dc:date>
    <item>
      <title>range check in awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/range-check-in-awk/m-p/2630408#M921170</link>
      <description>Hi Folks,&lt;BR /&gt;&lt;BR /&gt;   Is there any function (or piece of program developed by guru's like you) available for range check of the given value. For example the value of "a" should be between 0 and 45. I can do the check whether it is a interger or charcter with [0-9]+ or [a-z] string match. Thanks in adv.&lt;BR /&gt;&lt;BR /&gt;Kris</description>
      <pubDate>Wed, 12 Dec 2001 16:35:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/range-check-in-awk/m-p/2630408#M921170</guid>
      <dc:creator>Kris_5</dc:creator>
      <dc:date>2001-12-12T16:35:55Z</dc:date>
    </item>
    <item>
      <title>Re: range check in awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/range-check-in-awk/m-p/2630409#M921171</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;  I forgot to mention the value of a=10,20 or a=12-40 or a=10,20-40. I really don't want to use split function for this. Thanks,&lt;BR /&gt;&lt;BR /&gt;Kris</description>
      <pubDate>Wed, 12 Dec 2001 16:38:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/range-check-in-awk/m-p/2630409#M921171</guid>
      <dc:creator>Kris_5</dc:creator>
      <dc:date>2001-12-12T16:38:58Z</dc:date>
    </item>
    <item>
      <title>Re: range check in awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/range-check-in-awk/m-p/2630410#M921172</link>
      <description>There is an "if" function that does numeric comparisions:&lt;BR /&gt;{&lt;BR /&gt;if ( a &amp;gt; 0 )&lt;BR /&gt;   if ( a &amp;lt; 46 )&lt;BR /&gt;       [do stuff with a here]&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;--&lt;BR /&gt;mark</description>
      <pubDate>Wed, 12 Dec 2001 16:42:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/range-check-in-awk/m-p/2630410#M921172</guid>
      <dc:creator>Mark Greene_1</dc:creator>
      <dc:date>2001-12-12T16:42:10Z</dc:date>
    </item>
    <item>
      <title>Re: range check in awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/range-check-in-awk/m-p/2630411#M921173</link>
      <description>Test file contains a number, followed by that letter of the alphabet,...&lt;BR /&gt;&lt;BR /&gt;cat /tmp/a |awk 'BEGIN { FS=" " } ( $1 &amp;gt; 9 &amp;amp;&amp;amp; $1 &amp;lt; 13 ) || ( $1 == 2 ) || ( $1 == 4 ) { print $0 }'&lt;BR /&gt;&lt;BR /&gt;This prints 10 - 12, 2 and 4.&lt;BR /&gt;&lt;BR /&gt;Use BEDMAS (Brackets, Exponents, Division, Multiplication, Addition &amp;amp; Subtraction) to formulate the conditional.&lt;BR /&gt;&lt;BR /&gt;&amp;amp;&amp;amp; = AND&lt;BR /&gt;|| = OR&lt;BR /&gt;&lt;BR /&gt;I assume that the use of 'awk' in the title was correct?&lt;BR /&gt;&lt;BR /&gt;Share and Enjoy! Ian</description>
      <pubDate>Wed, 12 Dec 2001 16:46:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/range-check-in-awk/m-p/2630411#M921173</guid>
      <dc:creator>Ian Dennison_1</dc:creator>
      <dc:date>2001-12-12T16:46:19Z</dc:date>
    </item>
    <item>
      <title>Re: range check in awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/range-check-in-awk/m-p/2630412#M921174</link>
      <description>HI&lt;BR /&gt;  If i understand your requirement correctly you can do&lt;BR /&gt;if a=10,20&lt;BR /&gt;echo a | awk -F, '{ if ( $1 &amp;gt; 0 ) &amp;amp;&amp;amp; ( $1 &amp;lt; 45 ) &amp;amp;&amp;amp; ( $2 &amp;gt; 0 ) &amp;amp;&amp;amp; ( $2 &amp;lt; 45 ) {&lt;BR /&gt;   print $0&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt;...BPK...</description>
      <pubDate>Wed, 12 Dec 2001 16:50:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/range-check-in-awk/m-p/2630412#M921174</guid>
      <dc:creator>Praveen Bezawada</dc:creator>
      <dc:date>2001-12-12T16:50:13Z</dc:date>
    </item>
    <item>
      <title>Re: range check in awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/range-check-in-awk/m-p/2630413#M921175</link>
      <description>I gather that you just want to validate the sequence of ranges are valid. Since you don't want to use awk's split function for parsing the string, then I would recommend using perl.&lt;BR /&gt;&lt;BR /&gt;Here is an example-&lt;BR /&gt;&lt;BR /&gt;$mins="10,20-30,50";&lt;BR /&gt;$ok=1;&lt;BR /&gt;while($mins=~/[,]?(\d+)((-)(\d+))?/g) {&lt;BR /&gt; $ok=0 if $1 &amp;lt; 0 or $1 &amp;gt; 45;&lt;BR /&gt; next unless $4;&lt;BR /&gt; $ok=0 if $4 &amp;lt; 0 or $4 &amp;gt; 45;&lt;BR /&gt;}&lt;BR /&gt;print $ok;&lt;BR /&gt;&lt;BR /&gt;This will print 1 if $mins has a valid range of numbers, otherwise it will print 0.&lt;BR /&gt;&lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Wed, 12 Dec 2001 17:04:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/range-check-in-awk/m-p/2630413#M921175</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2001-12-12T17:04:32Z</dc:date>
    </item>
    <item>
      <title>Re: range check in awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/range-check-in-awk/m-p/2630414#M921176</link>
      <description>Make sure when you use FS you are using FS="[-,]" so you get ranges and individual integers.</description>
      <pubDate>Wed, 12 Dec 2001 17:39:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/range-check-in-awk/m-p/2630414#M921176</guid>
      <dc:creator>Jeff Machols</dc:creator>
      <dc:date>2001-12-12T17:39:46Z</dc:date>
    </item>
    <item>
      <title>Re: range check in awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/range-check-in-awk/m-p/2630415#M921177</link>
      <description>Hello Kris,&lt;BR /&gt;&lt;BR /&gt;I see you don't want to use the split function but in this instance where you need to sub-divide the , seperated fields into - seperated fields, split really is the simplest way - I don't see a better alternative. Assuming that you want to test each comma seperated range against your &amp;gt;=0 and &amp;lt;=45 criteria the following code should work fine. I wrote this into a shell script for simplicity:&lt;BR /&gt;&lt;BR /&gt;echo $1 | awk '&lt;BR /&gt;&lt;BR /&gt;{&lt;BR /&gt;   output = ""&lt;BR /&gt;   x = split($0, cs, ",")&lt;BR /&gt;   for (a = 1; a &amp;lt;= x; ++a)&lt;BR /&gt;   {&lt;BR /&gt;      y = split(cs[a], range, "-")&lt;BR /&gt;      if ( range[1] &amp;lt;=45 &amp;amp;&amp;amp; range[y] &amp;gt;= 0 )&lt;BR /&gt;         output = "OK"&lt;BR /&gt;&lt;BR /&gt;   }&lt;BR /&gt;&lt;BR /&gt;   print output&lt;BR /&gt;&lt;BR /&gt;}'&lt;BR /&gt;&lt;BR /&gt;Where $1 is your comma seperated string, such as 3,10-36,47 etc&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;Simon.</description>
      <pubDate>Thu, 13 Dec 2001 10:29:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/range-check-in-awk/m-p/2630415#M921177</guid>
      <dc:creator>Simon Abbott</dc:creator>
      <dc:date>2001-12-13T10:29:40Z</dc:date>
    </item>
    <item>
      <title>Re: range check in awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/range-check-in-awk/m-p/2630416#M921178</link>
      <description>Hi Kris,&lt;BR /&gt;&lt;BR /&gt;This is an awk script that doesn't use split:&lt;BR /&gt;&lt;BR /&gt;BEGIN{for (i=0;i&amp;lt;10;i++){numbers[i]=1};j=0;r=0;number=0;n=0}&lt;BR /&gt;{&lt;BR /&gt; for (i=1;i&amp;lt;=length(range);i++)&lt;BR /&gt; {&lt;BR /&gt;  char=substr(range,i,1)&lt;BR /&gt;  if (char in numbers)&lt;BR /&gt;  {&lt;BR /&gt;   number=number*10^(n++)+char&lt;BR /&gt;   if (i&lt;LENGTH&gt;&lt;/LENGTH&gt;    continue&lt;BR /&gt;  }&lt;BR /&gt;  if (char == "-")&lt;BR /&gt;  {&lt;BR /&gt;   r=1&lt;BR /&gt;   start=number&lt;BR /&gt;  }&lt;BR /&gt;  else&lt;BR /&gt;  {&lt;BR /&gt;   if (char == "," || i == length(range))&lt;BR /&gt;   {&lt;BR /&gt;    if (r == 1)&lt;BR /&gt;    {&lt;BR /&gt;     r=0&lt;BR /&gt;     for (num=start;num&lt;NUMBER&gt;&lt;/NUMBER&gt;      narray[j++]=num&lt;BR /&gt;    }&lt;BR /&gt;    narray[j++]=number&lt;BR /&gt;   }&lt;BR /&gt;  }&lt;BR /&gt;  number=0&lt;BR /&gt;  n=0&lt;BR /&gt; }&lt;BR /&gt; for (i=0;i&lt;J&gt;&lt;/J&gt; {&lt;BR /&gt;  if ( narray[i] == $0 )&lt;BR /&gt;  {&lt;BR /&gt;   print "In range"&lt;BR /&gt;   exit&lt;BR /&gt;  }&lt;BR /&gt; }&lt;BR /&gt; print "Not in range"&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;echo 25 | awk -f /tmp/range.awk range=1-5,7,10-20&lt;BR /&gt;Not in range&lt;BR /&gt;&lt;BR /&gt;# echo 15 | awk -f /tmp/range.awk range=1-5,7,10-20&lt;BR /&gt;In range&lt;BR /&gt;&lt;BR /&gt;Rgds, Robin</description>
      <pubDate>Thu, 13 Dec 2001 13:45:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/range-check-in-awk/m-p/2630416#M921178</guid>
      <dc:creator>Robin Wakefield</dc:creator>
      <dc:date>2001-12-13T13:45:39Z</dc:date>
    </item>
  </channel>
</rss>

