First Letter in a String to be capitalized


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting First Letter in a String to be capitalized
# 1  
Old 02-23-2010
First Letter in a String to be capitalized

Is there a way to cnvert first letter alone in a string to upper case.

For eg: diamond should be converted to Diamond.
Thanks in Advance,
Kinny
# 2  
Old 02-23-2010
using Perl:

Code:
print ucfirst("diamond");

cheers,
Devaraj Takhellambam
# 3  
Old 02-23-2010
using perl one liner
Code:
perl  -e "print ucfirst('diamond');"

# 4  
Old 02-23-2010
how's this....!

echo 'kinny' | sed -e 's/^\(.\)/\U\1/'
# 5  
Old 02-23-2010
or,

Code:
/home1->echo 'diamond' | awk '{sub(".",substr(toupper($0),1,1));print}'
Diamond
/home1->

# 6  
Old 02-23-2010
bash and tr :
Code:
s="diamond"
echo $(echo ${s:0:1} | tr [a-z] [A-Z])${s:1}

# 7  
Old 02-23-2010
using perl

Code:
echo "diamonds" | perl -wlne 'print "\u$_";'

Code:
o/p:-
Diamonds

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace specific letter in a file by other letter

Good afternoon all, I want to ask how to change some letter in my file with other letter in spesific line eg. data.txt 1 1 1 0 0 0 0 for example i want to change the 4th line with character 1. How could I do it by SED or AWK. I have tried to run this code but actually did not... (3 Replies)
Discussion started by: weslyarfan
3 Replies

2. Shell Programming and Scripting

Issue catching/reading 2 digits and 3 letter string between brackets

Hello I'm writing a handler for ffmpeg, and having troubles to catch some exceptions that may occour with certain files. In order to parse for video & subtitle maps, i've had to make the raw data easier to handle, until now this worked well, but basicly i've just been lucky... The input... (1 Reply)
Discussion started by: sea
1 Replies

3. Shell Programming and Scripting

Counting all words that start with a capital letter in a string using python dictionary

Hi, I have written the following python snippet to store the capital letter starting words into a dictionary as key and no of its appearances as a value in this dictionary against the key. #!/usr/bin/env python import sys import re hash = {} # initialize an empty dictinonary for line in... (1 Reply)
Discussion started by: royalibrahim
1 Replies

4. Shell Programming and Scripting

check index of a string by finding a letter in it

i would like to search for a letter in a string and get its index position. example: name='john' pos=$(expr index $name o) the result will be equal to 2 (2nd position) how do you make this thing not case sensitive? example: name='john' pos=$(expr index $name O) the... (1 Reply)
Discussion started by: kokoro
1 Replies

5. Shell Programming and Scripting

Trying to take a string and break each letter into a separate variable

I am trying to make a script that takes a word and each letter up and turns it into a separate variable. My code currently does not work but I feel I just need to tweak one thing that I am unsure of. (ex: if forum was typed in letter1=f; letter2=o; letter3=r;...) Thank you count=1; ... (7 Replies)
Discussion started by: crimputt
7 Replies

6. Shell Programming and Scripting

change each letter of a string

Is there a way to change each letter of a string to the next one in the alphabet, so that a becomes b and f becomes g, and digits become one unit bigger - 4 becomes 5 and 9 becomes 0. I want to change strings like ben123 to cfo234. (5 Replies)
Discussion started by: locoroco
5 Replies

7. Shell Programming and Scripting

Extract the letter from string

Hi, Pl help me. User is entering the values for the given input Enter keys: secret1 secret2 secret3 can i extract the last digit of each values in the keys.. here for ex. 1 2 3 can we get this using shell script? (22 Replies)
Discussion started by: balamv
22 Replies

8. Shell Programming and Scripting

Finding a letter in a string

How to check whether a particular string contains dot or not? Here I can not use grep as the string is not in a file. I will get this string from user input Thanks, (2 Replies)
Discussion started by: balamv
2 Replies

9. UNIX for Dummies Questions & Answers

If first letter of name is a-m do this if n-x do something else

so if I run echo $USER and the name is smithr i want to run command B to run because s is after m in the alphabet, but if the user is aldap I want command A to run because their first initial in the user name is in the first half of alphabet. how please? (2 Replies)
Discussion started by: glev2005
2 Replies

10. Shell Programming and Scripting

get only two letter from any string

I want get middle two latter of any string. Input: var="070108" output: var1="01" please help. (2 Replies)
Discussion started by: rinku
2 Replies
Login or Register to Ask a Question