|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hello all ,
I need to display a word with the first character in CAPS . that is , split then the display should be Split Thanks RC |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On 2006-08-22, aarcee wrote:
> Hello all , > > I need to display a word with the first character in CAPS . You mean CAP, not CAPS, if it is only one character. If you have the word in $word: case $word in a*) _UPR=A ;; b*) _UPR=B ;; c*) _UPR=C ;; d*) _UPR=D ;; e*) _UPR=E ;; f*) _UPR=F ;; g*) _UPR=G ;; h*) _UPR=H ;; i*) _UPR=I ;; j*) _UPR=J ;; k*) _UPR=K ;; l*) _UPR=L ;; m*) _UPR=M ;; n*) _UPR=N ;; o*) _UPR=O ;; p*) _UPR=P ;; q*) _UPR=Q ;; r*) _UPR=R ;; s*) _UPR=S ;; t*) _UPR=T ;; u*) _UPR=U ;; v*) _UPR=V ;; w*) _UPR=W ;; x*) _UPR=X ;; y*) _UPR=Y ;; z*) _UPR=Z ;; *) _UPR=${1%${1#?}} ;; esac word=$_UPR${word#?} printf "s\n" "$word" > that is , split then the display should be Split What display? Split how? Why? -- Chris F.A. Johnson, author <http://cfaj.freeshell.org> Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) ===== My code in this post, if any, assumes the POSIX locale ===== and is released under the GNU General Public Licence |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
aarcee schrieb: > Hello all , > > I need to display a word with the first character in CAPS . > > that is , split then the display should be Split > > Thanks > RC #!/bin/sh PATH=/bin:/usr/bin for arg do firstchar=`echo "$arg" | cut -c1` # assume echo -n does not print newline echo -n $firstchar | tr a-z A-Z echo "$arg" | sed -s s/^.// done Hubble |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On 21 Aug 2006 23:33:58 -0700, aarcee wrote:
> Hello all , > > I need to display a word with the first character in CAPS . > > that is , split then the display should be Split [...] With zsh: word=foo Word=${(C)word} (will captitalise every word in $word (turns " foo bar" into " Foo Bar"). With other shells: Word=$( awk ' BEGIN { print toupper(substr(ARGV[1], 1, 1)) \ tolower(substr(ARGV[1], 2)) exit }' "$word" ) Captitalises only the first character in $word. -- Stephane |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
aarcee <4mystudies@gmail.com> wrote:
> Hello all , > > I need to display a word with the first character in CAPS . > > that is , split then the display should be Split a='split' echo ${a|.capitalize} Ref: http://home.eol.ca/~parkw/index.html...eter_expansion -- William Park <opengeometry@yahoo.ca>, Toronto, Canada ThinFlash: Linux thin-client on USB key (flash) drive http://home.eol.ca/~parkw/thinflash.html BashDiff: Super Bash shell http://freshmeat.net/projects/bashdiff/ |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
aarcee wrote:
> Hello all , > > I need to display a word with the first character in CAPS . > > that is , split then the display should be Split GNU sed: bash:~$ echo 'split' | sed 's/./\u&/' Split bash:~$ echo 'cygwin split' | sed 's/\([^ ]\+\)/\u\1/g' Cygwin Split -- XC |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
aarcee wrote: > Hello all , > > I need to display a word with the first character in CAPS . > > that is , split then the display should be Split > > Thanks > RC if you have Python in your unix version, >>> "split".capitalize() 'Split' >>> |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
thanks a log for all the answers.
mik3 wrote: > aarcee wrote: > > Hello all , > > > > I need to display a word with the first character in CAPS . > > > > that is , split then the display should be Split > > > > Thanks > > RC > > if you have Python in your unix version, > >>> "split".capitalize() > 'Split' > >>> |
|
![]() |
| Outils de la discussion | |
|
|