i have tried using sed with "y" as follows:
fname="fwdBldCall"
nfw=`echo $fname | sed "y/[a-z]/[A-Z]/"`
echo "fname = $fname"
echo "nfw = $nfw"
this is what i get:
philip@thunder 267% fname="fwdBldCall"
philip@thunder 268% nfw=`echo $fname | sed "y/[a-z]/[A-Z]/"`
philip@thunder 269% echo $fname
fwdBldCall
philip@thunder 270% echo $nfw
fwdBldCAll
What am I doing wrong ?
Thanks in advance!
Notice the /./ at the beginning of the sed. In Korn shell you could do
this:
typeset -uL1 c=$fname
nfw=$c${fname#?}
which would be faster than sed.
> i have tried using sed with "y" as follows:
> fname="fwdBldCall"
> nfw=`echo $fname | sed "y/[a-z]/[A-Z]/"`
»sed« is overkill here. What about just using »tr«?
nfw=`echo $fname | tr a-z A-Z`
or
nfw=`echo $fname | tr [:lower:] [:upper:]`
Michael
You are using sed unnecessarily and incorrectly. I'll leave it to a
seder to correct your sed usage, but capitalizing the first char
of a variable is easy in ksh.
$ x=abcdef
$ typeset -uL1 f=$x
$ print "${f}${x#?}"
Abcdef
the typeset command creates a special variable that is uppercase,
Left aligned and one char long. ${vname#pattern} trims the first
occurrance of pattern from the start of $vname. '?' matches a single
character.
${x#?} trims the first char from $x and returns the resulting string
>
> Thanks in advance!
>
>
--
Dan Mercer
dame...@mmm.com
Opinions expressed herein are my own and may not represent those of my employer.
philip@thunder 383% echo $fname | tr a-z A-Z
FWDBWDIND
On Fri, 4 May 2001, Michael Velten wrote:
> Date: Fri, 4 MAY 2001 21:52:18 +0200
> From: Michael Velten <usene...@michnet.de>
> Newgroups: comp.unix.shell
> Subject: Re: Capitalize the first letter of a variable only: Kshell
> tr capitilizes all the letters ... i just want the first one to
> be capitilized
Oops, sorry. I should better go to bed. ;)
Forget my last posting and use the other internal ksh suggestions.
Michael