Inside a script I have 2 variables COMP=cy and PT=t. further down the same script I require at the same line to call those 2 variables the first time uppercase and after lowercase ${COMP}${PT}ACE,${COMP}${PT}ace. Can somebody help me
Thanks in advance
George Govotsis
gus2000
December 11, 2007, 2:47pm
2
There are a variety of ways to do what you suggest. The simplest is to create variables that the shell will convert to all uppercase or lowercase:
typeset -u COMP_UPPER PT_UPPER
typeset -l COMP_LOWER PT_LOWER
The variables above will always convert their values to uppercase or lowercase, respectively. Of course, you can also convert via other programs:
echo "$COMP" | tr '[a-z]' '[A-Z]'
echo "$COMP" | awk '{print toupper($0)}'
You get the idea.
#!/bin/ksh
a='foo'
typeset -uL1 b=${a}
echo "${b}${a#?}"
More on this here .
gus2000:
There are a variety of ways to do what you suggest. The simplest is to create variables that the shell will convert to all uppercase or lowercase:
typeset -u COMP_UPPER PT_UPPER
typeset -l COMP_LOWER PT_LOWER
The variables above will always convert their values to uppercase or lowercase, respectively. Of course, you can also convert via other programs:
echo "$COMP" | tr '[a-z]' '[A-Z]'
echo "$COMP" | awk '{print toupper($0)}'
You get the idea.
I guess the OP wanted the variable values to be capitalized - not the whole string to be UPPER-cased.
The OP will have to clarify!
SebaM6
December 11, 2007, 6:16pm
5
I guess you can also use syntax as
print $VARIABLE|sed 'y/[a-z]/[A-Z]'
funksen
December 13, 2007, 3:51am
6
or
tr "[:lower:]" "[:upper:]"
tr "[:upper:]" "[:lower:]"
i dont have any variable
i dont have any file
i just want to convert AJIT to ajit
can i do this in UNIX atraight away
zaxxon
October 16, 2008, 10:07am
8
@ajit.yadav83
There are plenty of examples above - you just have to change the echoing of a variable to echoing your string for example...