Hi All
I have a script which extracts values from a Database (A persons name) and puts it into a variable in my script IE: $NAME
However the Value in the DB is all in uppercase and contains the users first name and last name
EG:
> echo $NAME
GRAHAM BOYLE
>
What I need is only the persons first name to be displayed and it should be in lower case except for the first letter
EG:
> echo $NAME
Graham
>
Any help is very much appreciated.
Thanks
G.
zedex
May 20, 2009, 6:35am
2
which DB you are using ?? there are ways in DB to get value in upper, lower case
like in oracle you get upper, lower , initcap functions to do this so you do not need further processing on it ...
try to do that or search in forum
zedex:
which DB you are using ?? there are ways in DB to get value in upper, lower case
like in oracle you get upper, lower , initcap functions to do this so you do not need further processing on it ...
try to do that or search in forum
Hi
yes I am using an Oracle DB
However there are parts of the script Where I need the users full name in uppercase
I only want their first name now and the first letter to be in uppercase
Is this possible?
Regards
G.
echo 'jOE sHMOE' | nawk '{for(i=1;i<=NF;i++) {$i=tolower($i); sub(/./,toupper(substr($i,1,1)),$i)}}1'
If you have perl:
$
$ echo 'GRAHAM BOYLE' | perl -ne '{split; print ucfirst"\L$_[0]\n"}'
Graham
$
tyler_durden
thanks for all you replies
I have decide to use this
NAME=`echo "$NAME" | awk '{for(i=1;i<=NF;i++) {$i=tolower($i); sub(/./,toupper(substr($i,1,1)),$i)}}1'`
NAME=`echo "$NAME" | awk '{print $1}'`
Cheers
Guys
if you have just ONE word, you don't need 2 awk's:
echo 'jOE' | nawk '{$0=tolower($0);sub(/./,toupper(substr($0,1,1)),$0);print}'
Or if u just need the first name though u have two words for the name... just using one awk
echo 'jOE sHMOE' | nawk '{$1=tolower($1);sub(/./,toupper(substr($1,1,1)),$1);print $1}'