<?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: Increasing ASCII values in shell variables in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/increasing-ascii-values-in-shell-variables/m-p/4561393#M650013</link>
    <description>&lt;!--!*#--&gt;You can't use printf(1) but awk works:&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;(( char = 16#41 ))&lt;BR /&gt;while (( char &amp;lt;= 16#5a )); do&lt;BR /&gt;   awk -v char=$char 'BEGIN {printf "MYVAR%c\n", char }' /dev/null&lt;BR /&gt;   (( char += 1 ))&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;And you can put the whole loop in awk:&lt;BR /&gt;awk '&lt;BR /&gt;BEGIN{&lt;BR /&gt;   for (i = 0; i &amp;lt; 26; ++i)&lt;BR /&gt;      printf "MYVAR%c\n", i + 65&lt;BR /&gt;}' /dev/null</description>
    <pubDate>Tue, 12 Jan 2010 05:17:55 GMT</pubDate>
    <dc:creator>Dennis Handly</dc:creator>
    <dc:date>2010-01-12T05:17:55Z</dc:date>
    <item>
      <title>Increasing ASCII values in shell variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/increasing-ascii-values-in-shell-variables/m-p/4561384#M650004</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I have 2 questions that concerns giving ASCII values to shell variables. I need it for loop that increases the ASCII value of a variable each loop pass. I need something like that (I will use it for grep not echo):&lt;BR /&gt;&lt;BR /&gt;$ for right_char in A B C D E&lt;BR /&gt;&amp;gt; do&lt;BR /&gt;&amp;gt;    echo MYVAR${right_char}&lt;BR /&gt;&amp;gt; done&lt;BR /&gt;MYVARA&lt;BR /&gt;MYVARB&lt;BR /&gt;MYVARC&lt;BR /&gt;MYVARD&lt;BR /&gt;MYVARE&lt;BR /&gt;&lt;BR /&gt;However, if I want the loop to go on on the letters from A to Z, I would need either:&lt;BR /&gt;&lt;BR /&gt;1. A way to tell the for to go from A to Z, something like [A..B], is there such a construct?&lt;BR /&gt;&lt;BR /&gt;2. Define  right_char to hold ASCII code that I can increase with each loop pass with the simple + operator. What is the way to do that?&lt;BR /&gt;&lt;BR /&gt;The shell is a POSIX shell.&lt;BR /&gt;&lt;BR /&gt;Thanks for the answers.</description>
      <pubDate>Sat, 09 Jan 2010 17:30:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/increasing-ascii-values-in-shell-variables/m-p/4561384#M650004</guid>
      <dc:creator>yaron1</dc:creator>
      <dc:date>2010-01-09T17:30:53Z</dc:date>
    </item>
    <item>
      <title>Re: Increasing ASCII values in shell variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/increasing-ascii-values-in-shell-variables/m-p/4561385#M650005</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;You could use a tiny Perl snippet:&lt;BR /&gt;&lt;BR /&gt;# perl -le 'print "MYVAR$_" for (A..Z)'&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Sat, 09 Jan 2010 17:40:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/increasing-ascii-values-in-shell-variables/m-p/4561385#M650005</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2010-01-09T17:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: Increasing ASCII values in shell variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/increasing-ascii-values-in-shell-variables/m-p/4561386#M650006</link>
      <description>I actually need to use it in a grep command, not echo. I'm curious how to do it in shell. is there something equivalent to the Perl $_ for (A..Z)?&lt;BR /&gt;&lt;BR /&gt;Thanks.</description>
      <pubDate>Sat, 09 Jan 2010 21:36:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/increasing-ascii-values-in-shell-variables/m-p/4561386#M650006</guid>
      <dc:creator>yaron1</dc:creator>
      <dc:date>2010-01-09T21:36:34Z</dc:date>
    </item>
    <item>
      <title>Re: Increasing ASCII values in shell variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/increasing-ascii-values-in-shell-variables/m-p/4561387#M650007</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;&amp;gt; I actually need to use it in a grep command, not echo. &lt;BR /&gt;&lt;BR /&gt;If I understand correctly, you might do something like:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;VARS=$(perl -le 'print "MYVAR$_" for (A..Z)')&lt;BR /&gt;for X in ${VARS}&lt;BR /&gt;do&lt;BR /&gt;    grep ${X} file&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Sat, 09 Jan 2010 22:39:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/increasing-ascii-values-in-shell-variables/m-p/4561387#M650007</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2010-01-09T22:39:04Z</dc:date>
    </item>
    <item>
      <title>Re: Increasing ASCII values in shell variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/increasing-ascii-values-in-shell-variables/m-p/4561388#M650008</link>
      <description>&lt;!--!*#--&gt;$ n=0&lt;BR /&gt;$ echo 'abcdefghijklmnopqrstuvwxyz' | sed -e "s/.\{${n}\}\(.\).*/\1/"&lt;BR /&gt;a&lt;BR /&gt;&lt;BR /&gt;$ n=1&lt;BR /&gt;$ echo 'abcdefghijklmnopqrstuvwxyz' | sed -e "s/.\{${n}\}\(.\).*/\1/"&lt;BR /&gt;b&lt;BR /&gt;&lt;BR /&gt;[...]&lt;BR /&gt;&lt;BR /&gt;$ n=24&lt;BR /&gt;$ echo 'abcdefghijklmnopqrstuvwxyz' | sed -e "s/.\{${n}\}\(.\).*/\1/"&lt;BR /&gt;y&lt;BR /&gt;&lt;BR /&gt;$ n=25&lt;BR /&gt;$ echo 'abcdefghijklmnopqrstuvwxyz' | sed -e "s/.\{${n}\}\(.\).*/\1/"&lt;BR /&gt;z&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;It's easier in DCL:&lt;BR /&gt;&lt;BR /&gt;alp $ n = 12&lt;BR /&gt;&lt;BR /&gt;alp $ write sys$output f$extract( n, 1, "abcdefghijklmnopqrstuvwxyz")&lt;BR /&gt;m&lt;BR /&gt;&lt;BR /&gt;Or, more cryptically:&lt;BR /&gt;&lt;BR /&gt;alp $ chr=""&lt;BR /&gt;alp $ chr[ 0, 8] = 97+ n&lt;BR /&gt;alp $ write sys$output chr&lt;BR /&gt;m&lt;BR /&gt;&lt;BR /&gt;As usual, many things are possible.</description>
      <pubDate>Sat, 09 Jan 2010 23:51:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/increasing-ascii-values-in-shell-variables/m-p/4561388#M650008</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2010-01-09T23:51:57Z</dc:date>
    </item>
    <item>
      <title>Re: Increasing ASCII values in shell variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/increasing-ascii-values-in-shell-variables/m-p/4561389#M650009</link>
      <description>God, must be an MIS major.  Awful.</description>
      <pubDate>Sun, 10 Jan 2010 03:53:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/increasing-ascii-values-in-shell-variables/m-p/4561389#M650009</guid>
      <dc:creator>Michael Steele_2</dc:creator>
      <dc:date>2010-01-10T03:53:18Z</dc:date>
    </item>
    <item>
      <title>Re: Increasing ASCII values in shell variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/increasing-ascii-values-in-shell-variables/m-p/4561390#M650010</link>
      <description>I assume you can use printf(1) and printf within awk(1) with the %c format to print out chars.&lt;BR /&gt;You could also use an array of chars like Steven's:&lt;BR /&gt;set -A chars A B C D E F ...&lt;BR /&gt;echo $chars[0]</description>
      <pubDate>Sun, 10 Jan 2010 06:19:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/increasing-ascii-values-in-shell-variables/m-p/4561390#M650010</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2010-01-10T06:19:17Z</dc:date>
    </item>
    <item>
      <title>Re: Increasing ASCII values in shell variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/increasing-ascii-values-in-shell-variables/m-p/4561391#M650011</link>
      <description>Here's a couple of all-shell methods:&lt;BR /&gt; &lt;BR /&gt;For just the list shown in the original question:&lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;for CHR in A B C D E F G H I J K L M N O P Q R S T U V W X Y Z&lt;BR /&gt;do&lt;BR /&gt;   echo MYVAR$CHR&lt;BR /&gt;done&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;#################&lt;BR /&gt; &lt;BR /&gt;For a numeric method:&lt;BR /&gt; &lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;set -A AZ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z&lt;BR /&gt;CNT=0&lt;BR /&gt;while [ $CNT -le 25 ]&lt;BR /&gt;do&lt;BR /&gt;   echo MYVAR${AZ[$CNT]}&lt;BR /&gt;   CNT=$((CNT+1))&lt;BR /&gt;done&lt;BR /&gt; &lt;BR /&gt;In the second example, the CHR array can be referenced with an number between 0-25. Insert a dummy value before "A" to change the index to 1-26.&lt;BR /&gt; &lt;BR /&gt;The grep requirement is not clear. If you are looking for all matches for MYVAR ending with any char A thru Z, this will do it on one line: &lt;BR /&gt; &lt;BR /&gt;grep MYAR[A-Z] some_file</description>
      <pubDate>Sun, 10 Jan 2010 19:38:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/increasing-ascii-values-in-shell-variables/m-p/4561391#M650011</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2010-01-10T19:38:22Z</dc:date>
    </item>
    <item>
      <title>Re: Increasing ASCII values in shell variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/increasing-ascii-values-in-shell-variables/m-p/4561392#M650012</link>
      <description>maybe you could get use of this bash feature, I don't know what are you trying to accomplish:&lt;BR /&gt;&lt;BR /&gt;# echo {1,2,3}{a,b,c}&lt;BR /&gt;1a 1b 1c 2a 2b 2c 3a 3b 3c&lt;BR /&gt;#&lt;BR /&gt;</description>
      <pubDate>Mon, 11 Jan 2010 14:00:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/increasing-ascii-values-in-shell-variables/m-p/4561392#M650012</guid>
      <dc:creator>Viktor Balogh</dc:creator>
      <dc:date>2010-01-11T14:00:14Z</dc:date>
    </item>
    <item>
      <title>Re: Increasing ASCII values in shell variables</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/increasing-ascii-values-in-shell-variables/m-p/4561393#M650013</link>
      <description>&lt;!--!*#--&gt;You can't use printf(1) but awk works:&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;(( char = 16#41 ))&lt;BR /&gt;while (( char &amp;lt;= 16#5a )); do&lt;BR /&gt;   awk -v char=$char 'BEGIN {printf "MYVAR%c\n", char }' /dev/null&lt;BR /&gt;   (( char += 1 ))&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;And you can put the whole loop in awk:&lt;BR /&gt;awk '&lt;BR /&gt;BEGIN{&lt;BR /&gt;   for (i = 0; i &amp;lt; 26; ++i)&lt;BR /&gt;      printf "MYVAR%c\n", i + 65&lt;BR /&gt;}' /dev/null</description>
      <pubDate>Tue, 12 Jan 2010 05:17:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/increasing-ascii-values-in-shell-variables/m-p/4561393#M650013</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2010-01-12T05:17:55Z</dc:date>
    </item>
  </channel>
</rss>

