Make the first character uppercase


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Make the first character uppercase
# 1  
Old 11-18-2010
Make the first character uppercase

Input:
Code:
hello
world
monkey

Output should be:
Code:
Hello
World
Monkey

How can it be done with perl,sed,awk or bash?
# 2  
Old 11-18-2010
Code:
awk -F "" '{$1=toupper($1)}1' OFS= file

# 3  
Old 11-18-2010
Quote:
Originally Posted by Franklin52
Code:
awk -F "" '{$1=toupper($1)}1' OFS= file

Wow, cool...would you please explain a little bit for this code?
# 4  
Old 11-18-2010
Code:
sed 's/^./\u&/' file

# 5  
Old 11-18-2010
Hi,
Code:
$ perl -ne 'print ucfirst' infile

Regards,
Birei
# 6  
Old 11-18-2010
Code:
perl -ne 'print ucfirst($_)' file

# 7  
Old 11-18-2010
Quote:
Originally Posted by kevintse
Wow, cool...would you please explain a little bit for this code?
Code:
awk -F "" '{$1=toupper($1)}1' OFS= file

Explanation:
Code:
awk -F ""	# set fieldseparator to "", now a field is one character
$1=toupper($1)	# make the first character uppercase
1		# if the condition is true (1 = true) without an action, awk prints the current line per default
OFS=		# set output field separator to ""

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cannot find correct syntax to make file name uppercase letters

I have a file name : var=UsrAccChgRpt I want to make them upper case. Tried: $var | tr Error: tr: Invalid combination of options and Strings. Usage: tr | -ds | -s | -ds | -s ] String1 String2 tr { -d | -s | -d | -s } String1 Could you please help. I am using AIX... (2 Replies)
Discussion started by: digioleg54
2 Replies

2. Shell Programming and Scripting

Add character to specific columns using sed or awk and make it a permanent change

Hi, I am writing a shell script where I want that # should be added in all those lines as the first character where the pattern matches. file has lot of functions defined a.sh #!/bin/bash fn a { beautiful evening sunny day } fn b { } fn c { hello world .its a beautiful day ... (12 Replies)
Discussion started by: ashima jain
12 Replies

3. AIX

Bison -pap_expr_yy invalid character:% unexpected "identifier" while running make for Apache2.4.3 64

The Follwing packages are installed on my AIX 6.1 box gcc-4.7.2-1 gcc-c++-4.7.2-1 gcc-cpp-4.7.2-1 gcc-gfortran-4.7.2-1 libgcc-4.7.2-1 libgomp-4.7.2-1 libstdc++-4.7.2-1 libstdc++-devel-4.7.2-1 gmp-5.0.5-1 libmpc-1.0.1-2 libmpc-devel-1.0.1-2 libmpcdec-1.2.6-1 libmpcdec-devel-1.2.6-1... (0 Replies)
Discussion started by: Ashish Gupta
0 Replies

4. Shell Programming and Scripting

making the first character of word using uppercase using awk and sed

I want to make the first character of some words to be uppercase. I have a file like the one below. uid,givenname,sn,cn,mail,telephonenumber mattj,matt,johnson,matt johnson,mattj@gmail.com markv,mark,vennet,matt s vennet,markv@gmail.com mikea,mike,austi,mike austin,mike@gmail.com I want... (3 Replies)
Discussion started by: matt12
3 Replies

5. Shell Programming and Scripting

Make pwd print escape character

I decided I wanted to have the cd command print my full working directory after each cd command, so I put this cw command in .bashrc as a function. cw () { cd "${1}" pwd }While this works I would like pwd to print escapes when a space in a directory name exists. This would... (7 Replies)
Discussion started by: jelloir
7 Replies

6. Shell Programming and Scripting

Uppercase/lowercase comparison of one character per line with awk??

Another frustrating scripting problem from a biologist trying to manipulate a file with several millions line. For each of the line I need to compare the uppercase A or C or G or T with the lowercase a or c or g or t. If there are more uppercases, a + should be added to a new column, otherwise a -... (10 Replies)
Discussion started by: ivpz
10 Replies

7. UNIX for Dummies Questions & Answers

make script treat * as a regular character

I need a script that reads the out put of a command (softwareupdate --list) and will tally up the number of asterisks in the output and tell me how many there were. How do I go about getting my script to treat asterisks as a regular character and not a wildcard or some other operator? (8 Replies)
Discussion started by: glev2005
8 Replies

8. Shell Programming and Scripting

only uppercase first character?

should be a simple question, I am trying to uppercase every first character in a word on the list. abc google cnn services My first thought was sed 'y/^/^/', but it changed all the characters, not just the first character. any thoughts? (7 Replies)
Discussion started by: fedora
7 Replies

9. UNIX for Dummies Questions & Answers

make uppercase

If in a script I am taking an input (R201) for example and assigning it to a variable, how would I change the R to uppercase if it was keyed in as r201? I can't seem to get it to work with toupper (4 Replies)
Discussion started by: kirkm76
4 Replies

10. Shell Programming and Scripting

How To Make Decimal Point Fall On The 15th Character On The Screen

If i have a variable which is a decimal number, i.e 34.05 How can you make decimal point fall on the 15th character on the screen? Or any other that you can specify? Can you do it using sed or awk? (3 Replies)
Discussion started by: Vozx
3 Replies
Login or Register to Ask a Question