Shell script to convert to Title case


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Shell script to convert to Title case
# 1  
Old 06-21-2007
Shell script to convert to Title case

I need a shell script which will convert the given string to Title case.




E.g "hi man"


to "Hi man"
# 2  
Old 06-21-2007
Code:
$ echo "hi man" | perl -ane ' foreach $wrd ( @F ) { print ucfirst($wrd)." "; } print "\n" ; '
Hi Man

# 3  
Old 06-21-2007
this is good but pls tell the logic in perl part.



also can it be done purely in shell script (+ awk, sed like tat) without any help from other languages like perl, python, etc?
# 4  
Old 06-21-2007
I have a 2 step process:

a=`echo hi man | cut -c1 | tr [:lower:] [:upper:]`
echo hi man | sed "s/./$a/"
# 5  
Old 06-21-2007
Quote:
Originally Posted by SankarV
this is good but pls tell the logic in perl part.



also can it be done purely in shell script (+ awk, sed like tat) without any help from other languages like perl, python, etc?
Code:
echo "hi man" | perl -ane ' foreach $wrd ( @F ) { print ucfirst($wrd)." "; } print "\n" ; '

a option splits the input with space as separator and assign the splitted words in array F.
Loop through the array and ucfirst function capitalizes the first character of the word
# 6  
Old 06-22-2007
an awk soln

Code:
echo "hi man" | awk '{printf("%s%s\n",toupper(substr($0,1,1)),substr($0,2))}'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help need to convert bi-lingual files in sub-title format

I have a large number of files in the standard subtitle format with the additional proviso that the files are bi-lingual i.e. English and a second language: in this case Hindi. A small sample is given below: 00 04 07 08 00 04 11 00 I mean very high fever... He even vomited. 00 04 07 08 00... (6 Replies)
Discussion started by: gimley
6 Replies

2. Shell Programming and Scripting

Convert text between exact matching patterns to Title case

Hi Folks, I have a large text file with multiple similar patterns on each line like: blank">PATTERN1 some word PATTERN2 title=">PATTERN1 some word PATTERN2 blank">PATTERN1 another word PATTERN2 title=">PATTERN1 another word PATTERN2 blank">PATTERN1 one more time PATTERN2 title=">PATTERN1... (10 Replies)
Discussion started by: martinsmith
10 Replies

3. UNIX for Advanced & Expert Users

Shell script to convert words to Title case

Hi :) I have a .txt file with thousands of words. I was wondering if i could use a simple sed or awk command to convert / replace all words in the text file to Title Case format ? Example: from: this is line one this is line two this is line three to desired output: This Is Line... (8 Replies)
Discussion started by: martinsmith
8 Replies

4. UNIX for Dummies Questions & Answers

To convert Lower case to Upper Case

There is a script where we pass the parameter in lower case: say: . ./scriptName pArameter #!/bin/ksh echo "`date` Entering $0 Reloading the $1 table " mname1=$1 (code to login MYSQL Database) Truncate table $mname1; exit ! Since now there is a limitaion of MYSQL that it accept... (5 Replies)
Discussion started by: ambarginni
5 Replies

5. Shell Programming and Scripting

Perl - Title Case after apostrophe

I've got: $string =~ s/(\w+)/\u\L$1/g; Which capitalizes each word in the string. The problem is if I have a string with an apostrophe the first letter after it gets capitalized as well. So Bob's becomes Bob'S. Thanks for any quick fixes! (4 Replies)
Discussion started by: mjmtaiwan
4 Replies

6. Shell Programming and Scripting

Script to Convert Upper case to Lower case

Hi All I have a script which extracts values from a Database (A persons name) and puts it into a variable in my script IE: $NAME However the Value in the DB is all in uppercase and contains the users first name and last name EG: > echo $NAME GRAHAM BOYLE > What I need is only the... (7 Replies)
Discussion started by: grahambo2005
7 Replies

7. Shell Programming and Scripting

convert upper case to lower case in ascript

I have a package to install and the installation script which does it . The files/directories names in the script are all lower case but the actual package has everything in upper case - file names, directories . I don't want to rename directories and files in the package - it has a lot of them . ... (2 Replies)
Discussion started by: vz6zz8
2 Replies

8. Shell Programming and Scripting

Shell/Perl script to convert to Capitalize case

I need a shell script which will convert the given string within a <title> tag to Capitalize case. E.g "<title>hi man: check this out</title>" to "<title>Hi Man: Check This Out</title>" (11 Replies)
Discussion started by: parshant_bvcoe
11 Replies

9. Shell Programming and Scripting

how to convert value in a variable from upper case to lower case

Hi, I have a variable $Ctrcd which contains country names in upper case and i want to convert them into lower case. I have tried so many solutions from already existing threads but couldn't get the correct one. Can anybody help me with this..... Thanks a lot.. (2 Replies)
Discussion started by: manmeet
2 Replies

10. UNIX for Dummies Questions & Answers

lower case to upper case string conversion in shell script

How can convert a Lower case variable value to an upper case in the kron shell script. (3 Replies)
Discussion started by: dchalavadi
3 Replies
Login or Register to Ask a Question