Operating System - HP-UX
1827458 Members
5011 Online
109965 Solutions
New Discussion

Coverting lower case to upper case in a script?

 
SOLVED
Go to solution
Scott Dunkley
Regular Advisor

Coverting lower case to upper case in a script?

I am trying to covert user input from lower/mixed case to upper case in a script and write it back to a variable. i am doing :

print -n 'what is your name: '
read NAME
awk -v NAME=$NAME '
{
toupper(NAME)
}'
echo $NAME
Better to regret something you have done, than something you havn't
6 REPLIES 6
Rainer von Bongartz
Honored Contributor

Re: Coverting lower case to upper case in a script?


so what is your question ????

Regards
rainer
He's a real UNIX Man, sitting in his UNIX LAN making all his UNIX plans for nobody ...
harry d brown jr
Honored Contributor
Solution

Re: Coverting lower case to upper case in a script?

Scott,

Why not

[root]pbctst: echo "This is a Test"|tr "[a-z]" "[A-Z]"
THIS IS A TEST


[root]pbctst: BNAME="this is a Test"
[root]pbctst: echo $BNAME
this is a Test
[root]pbctst: BNAME=`echo $BNAME|tr "[a-z]" "[A-Z]"`
[root]pbctst: echo $BNAME
THIS IS A TEST
[root]pbctst:


live free or die
harry
Live Free or Die
harry d brown jr
Honored Contributor

Re: Coverting lower case to upper case in a script?

Scott,

So for your example:

print -n 'what is your name: '
read NAME
NAME=`echo $NAME|tr "[a-z]" "[A-Z]"`

will upcase your variable NAME


live free or die
harry


Live Free or Die
James R. Ferguson
Acclaimed Contributor

Re: Coverting lower case to upper case in a script?

Hi Scott:

# UPPER=`echo "This Is In Mixed Case"|awk '{print toupper($0)}'`

# UPPER=`echo "This also"|tr -s '[:lower:]' '[:upper:]'`

Regards!

...JRF...
H.Merijn Brand (procura
Honored Contributor

Re: Coverting lower case to upper case in a script?

l1:/u/usr/merijn 108 > perl -e 'print "What is your name? ";$n=uc scalar ;print "Your name is: $n"'
What is your name? Wubbo Ockels
Your name is: WUBBO OCKELS
l1:/u/usr/merijn 109 >
Enjoy, Have FUN! H.Merijn
Scott Dunkley
Regular Advisor

Re: Coverting lower case to upper case in a script?

Thanks, all work really well, went for the basic idea in the end of using:

typset -u NAME
print -n 'name: '
read NAME
echo $NAME
Better to regret something you have done, than something you havn't