PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > first letter of the word in CAPS
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

first letter of the word in CAPS

Réponse
 
LinkBack Outils de la discussion
Vieux 22/08/2006, 07h33   #1
aarcee
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut first letter of the word in CAPS

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

  Réponse avec citation
Vieux 22/08/2006, 08h04   #2
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: first letter of the word in CAPS

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
  Réponse avec citation
Vieux 22/08/2006, 08h06   #3
Hubble
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: first letter of the word in CAPS


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

  Réponse avec citation
Vieux 22/08/2006, 09h39   #4
Stephane Chazelas
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: first letter of the word in CAPS

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
  Réponse avec citation
Vieux 22/08/2006, 23h59   #5
William Park
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: first letter of the word in CAPS

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/
  Réponse avec citation
Vieux 23/08/2006, 01h06   #6
Xicheng Jia
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: first letter of the word in CAPS

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

  Réponse avec citation
Vieux 23/08/2006, 13h38   #7
mik3
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: first letter of the word in CAPS


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'
>>>


  Réponse avec citation
Vieux 24/08/2006, 07h39   #8
aarcee
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: first letter of the word in CAPS

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'
> >>>


  Réponse avec citation
Vieux 24/08/2006, 07h39   #9
aarcee
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: first letter of the word in CAPS

thanks a lot 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'
> >>>


  Réponse avec citation
Vieux 24/08/2006, 21h06   #10
bsh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: first letter of the word in CAPS


aarcee wrote:
> I need to display a word with the first character in CAPS .


You haven't mentioned which shell.

=Brian

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 19h59.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12124 seconds with 18 queries