How u convert string "hi pravin how are you?" to
"Hi Pravin How Are You?"

Answers were Sorted based on User's Feedback



How u convert string "hi pravin how are you?" to "Hi Pravin How Are You?" ..

Answer / nachikethas

use a perl one liner like this

perl -e '$var="hi pravin how are you";@arr=split("
",$var);foreach $wrd(@arr){print ucfirst($wrd)." ";}'

Is This Answer Correct ?    8 Yes 5 No

How u convert string "hi pravin how are you?" to "Hi Pravin How Are You?" ..

Answer / padmakumar

The file "test" contains "hi pravin how are you?".

sed -e "s/^[a-z]/\U&/" -e "s/[[:space:]][a-z]/ \U&/g" test

Is This Answer Correct ?    5 Yes 2 No

How u convert string "hi pravin how are you?" to "Hi Pravin How Are You?" ..

Answer / vipul dalwala

echo "hi pravin how are you?" | awk 'BEGIN { ORS = ""
upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
lower = "abcdefghijklmnopqrstuvwxyz" }
{
for (i = 1; i <= NF; i++) {
FC = substr($i, 1, 1)
if (C = index(lower, FC))
FC = substr(upper, C, 1)
print FC substr($i,2) " "
}
print "\n"
}'

Is This Answer Correct ?    3 Yes 1 No

How u convert string "hi pravin how are you?" to "Hi Pravin How Are You?" ..

Answer / saravanan

$line = "hi Praveen How are you";

$line =~ s/\b(\w+)\b/ucfirst($1)/e;


print $line;

Is This Answer Correct ?    2 Yes 0 No

How u convert string "hi pravin how are you?" to "Hi Pravin How Are You?" ..

Answer / mahfooz

echo hi praveen how are you | tr ' ' '\n' | perl -n -
e 'print "\u$_"' | tr '\n' ' '

Is This Answer Correct ?    1 Yes 0 No

How u convert string "hi pravin how are you?" to "Hi Pravin How Are You?" ..

Answer / manish yadav

echo hi praveen how are you|sed 's/ [a-z]/\U&/g'|sed 's/^[a-
z]/\U&/g'

Is This Answer Correct ?    9 Yes 11 No

How u convert string "hi pravin how are you?" to "Hi Pravin How Are You?" ..

Answer / pravin

Dear amlan Iwant answer which work for any string given.

Is This Answer Correct ?    7 Yes 13 No

How u convert string "hi pravin how are you?" to "Hi Pravin How Are You?" ..

Answer / sonia

Use perl :-)

msg="hi praveen how are you"
msg=`echo $msg | perl -n -e 'print ucfirst(lc);'`

Is This Answer Correct ?    4 Yes 10 No

How u convert string "hi pravin how are you?" to "Hi Pravin How Are You?" ..

Answer / manuswami

echo "hi praveen how are you"|sed -e 's/
[a-z]/\U&/g'\;'s/^[a-z]/\U&/g'

Is This Answer Correct ?    9 Yes 16 No

How u convert string "hi pravin how are you?" to "Hi Pravin How Are You?" ..

Answer / amlan

sed 's/hi pravin how are you?/Hi Pravin How Are You?/g'
filename

Is This Answer Correct ?    15 Yes 26 No

Post New Answer

More Shell Script Interview Questions

How do we delete all blank lines in a file?

0 Answers  


Can you write a script to portray how set –x works?

0 Answers  


Is powershell a language?

0 Answers  


In shell scripting if text is surrounded by single quotes what does it denotes?

3 Answers  


How to create environment variables?What are the conditions for creating variables?

1 Answers   Infosys, Wipro,






What are filters explain sort with all the options available?

0 Answers  


Is cmd a shell?

0 Answers  


What is Path variable?What is its use?

1 Answers  


I have to write Shells (Linux + Unix)for publishing packages and reports. Is it possible ? What are the differents executable programs ineed to call ?

0 Answers  


What is the best shell scripting language?

0 Answers  


How to open a read-only file in the shell?

0 Answers  


How do I open a jshell in cmd?

0 Answers  


Categories