AWK - changing first char from small to upper


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers AWK - changing first char from small to upper
# 1  
Old 01-15-2012
AWK - changing first char from small to upper

I need to write script in AWK, changing first char from a line from lower to upper.
I found function toupper etc. but have no idea how to sent only first char from every line instead of the whole line. Anyone has any idea?

//
Sorry for my englishSmilie
# 2  
Old 01-15-2012
Hi bbqtoss,

What about a space as first char, or a paretheses?

Regards,
Birei
# 3  
Old 01-15-2012
Just extract the first character from the line using substr() and after converting to uppercase, just concatenate with the remaining part.
# 4  
Old 01-15-2012
An example might help:

Code:
awk '{ print toupper( substr( $0, 1, 1 ) ) substr( $0, 2 ); }' input-file >output-file

converts the first character of every record to uppercase (if it is lower) and then prints the line.
# 5  
Old 01-16-2012
try this:
Code:
awk -vFS="" -vOFS="" '{$1=toupper($1);print $0}' filename

# 6  
Old 01-16-2012
Quote:
Originally Posted by tarun_agrawal
try this:
Code:
awk -vFS="" -vOFS="" '{$1=toupper($1);print $0}' filename

I believe it will not satisfy his requirement:
the proof for it's failure:
Code:
echo hiahihi|awk '{FS="";print $1}'
hiahihi
echo hiahihi|awk '{FS="";OFS="";print $1}'
hiahihi

so, even if you apply
Code:
toupper()

for $1 it will convert whole string to uppercase, but his requirement is to make the first letter aslone uppercase.
# 7  
Old 01-16-2012
Quote:
Originally Posted by pandeesh
I believe it will not satisfy his requirement:
the proof for it's failure:
Code:
echo hiahihi|awk '{FS="";print $1}'
hiahihi
echo hiahihi|awk '{FS="";OFS="";print $1}'
hiahihi

so, even if you apply
Code:
toupper()

for $1 it will convert whole string to uppercase, but his requirement is to make the first letter aslone uppercase.
Dear Pandeesh,

Pls try to run exact command that I have published not yours modifed version

Code:
awk -vFS="" -vOFS="" '{$1=toupper($1);print $0}' filename

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk: get upper and lower bound per group

Hi all, I've data as: 22 51018157 51018157 exonic CHKB nonsynonymous SNV 22 51018204 51018204 exonic CHKB nonsynonymous SNV 22 51018428 51018428 exonic CHKB nonsynonymous SNV 22 51018814 51018814 ... (4 Replies)
Discussion started by: genome
4 Replies

2. Shell Programming and Scripting

awk sed to repeat every character on same position from the upper line replacing whitespace

Hello is it possible with awk or sed to replace any white space with the previous line characters in the same position? I am asking this because the file I have doesn't always follow a pattern. For example the file I have is the result of a command to obtain windows ACLs: icacls C:\ /t... (5 Replies)
Discussion started by: nakaedu
5 Replies

3. Shell Programming and Scripting

Lower to upper..tr + awk ?

I have a file that has a pattern 2 lines, blanktwo line If encountering the first line, the 2nd line need to be converted to UPPERCASE...or...conver the 2nd line after ablank into uppercase Is there a 'tr' function in awk..(probably the best tool over sed) ? i.e. ......................... (6 Replies)
Discussion started by: stevie_velvet
6 Replies

4. Shell Programming and Scripting

awk small discussion on array

Hi...all I want to pass array name for some function using loop anyone is having idea ? here is scenario echo | awk ' BEGIN{ A1="foo1" A2="foo2" A3="foo3" } function test1(a,b,c){ print a,b,c ... (10 Replies)
Discussion started by: Akshay Hegde
10 Replies

5. Shell Programming and Scripting

Problem with upper and lowercase in awk

My awk (GNU Awk 3.1.8 on Ubuntu 12.04) seems to ignore case. cat file abc ABC aBc 123 awk '//&&//{print $0,"";next}{print $0,""}' file My result:abc ABC aBc 123 Correct result:abc ABC aBc 123 (6 Replies)
Discussion started by: Jotne
6 Replies

6. Programming

Small query regarding function "char * strerror(int errnum)"

As this function returns the address of the string corressponding to the errno value provided to it. Can someone please let me know where, in the memory, it could be (on freeBSD). The MAN page tells under the BUG section that "For unknown error numbers, the strerror() function will return its... (5 Replies)
Discussion started by: Praveen_218
5 Replies

7. Shell Programming and Scripting

[Solved] Changing to upper case in csh

How can I change a string contained in a variable to upper case using csh ??? ---------- Post updated at 08:39 AM ---------- Previous update was at 08:29 AM ---------- I think I've got it, using tr has solved the problem set opt = ` echo $opt | tr "" "" ` (1 Reply)
Discussion started by: kristinu
1 Replies

8. UNIX for Dummies Questions & Answers

small doubt in awk

Hi Guys, I have a small problem with awk. I want to search { and } at a particular position in a string using awk. I tried echo "hello{hi" | awk '{if(substr($0,6,1)=="{"){print "TRUE"}}' but no success :mad: i know it can be done in many ways and i know them also.. but my... (6 Replies)
Discussion started by: vidyadhar85
6 Replies

9. UNIX for Dummies Questions & Answers

A small AWK problem

I have a file tmp.out with contents: 2008-08-09 05:11:01 2008-08-09 08:52:59 2008-08-11 12:08:34 2008-08-11 12:15:40 I want the output to be: 3|0|1|71|2008-08-09 05:11:01|2008-08-30 11:19:28 4|0|1|71|2008-08-09 08:52:59|2008-08-30 11:19:28 5|0|1|71|2008-08-11 12:08:34|2008-08-30 11:19:28... (6 Replies)
Discussion started by: ChicagoBlues
6 Replies

10. UNIX for Dummies Questions & Answers

replacing all 4 first upper char of every rec to lowercase ?

I have a file where some records have been updated the wrong way and need to fix it quickly since the amount can be alot. Every record where any of the first 4 characters are in upper case need to be changed to lowercase. Records can have '#' in position-1 for comments. These musn't be... (2 Replies)
Discussion started by: Browser_ice
2 Replies
Login or Register to Ask a Question