Operating System - HP-UX
1833704 Members
3303 Online
110062 Solutions
New Discussion

Auto increment a character in shell

 
SOLVED
Go to solution
Chua Wen Ching
Regular Advisor

Auto increment a character in shell

I had some problems on running the script below:

inc.sh
-------
str1="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
str2="BCDEFGHIJKLMNOPQRSTUVWXYZA"
pos=`expr index $str1 $char`
char=`expr substr $str2 $pos 1`
echo $char

i want to use the script to autogenerate a character in bourne shell. I am using hp-ux 10.20. Actually i found out a shorter way, but i want to know what is the solution for the inc.sh above. Thank you.
wenching
3 REPLIES 3
harry d brown jr
Honored Contributor
Solution

Re: Auto increment a character in shell

echo `expr $RANDOM % 26` `expr $RANDOM % 26` | awk '{ alphabet = "abcdefghijklmnopqrstuvwxyz"; printf("%s%s\n", substr(alphabet,$1,1), substr(alphabet,$2,1));}'


live free or die
harry

Live Free or Die
Chua Wen Ching
Regular Advisor

Re: Auto increment a character in shell

Thanks a lot. The codes really help in to solve a lot of problems.
wenching
H.Merijn Brand (procura
Honored Contributor

Re: Auto increment a character in shell

PC03:/W 508 $ perl -le '$a="a";print++$a'
b
PC03:/W 509 $
Enjoy, Have FUN! H.Merijn