change small letters to capital

hi guys, I know this might be very simple for u but not for me.
I simply want to print the active users, changeing the first letter in their names to capital. i guess sed it's useful but don't know how to find the correspondign capital letter and don't know how to change just the first letter.......
10x

Here's one way to do it:

while IFS=: read UN JUNK
do
    typeset -u -L1 f=$UN
    print ${f}${UN#@([a-z])}
done < /etc/passwd

10x a lot, but isn't there a simpler way to do it? maybe awk combined with sed or somethin', this looks too hard for me......

i think i have to do soemthin with sort -f

nawk -F: '{ print toupper(substr ($1,1,1)) substr ($1,2) }' /etc/passwd

Why would you need to sort the file in the first place?

I just saw in a tutorial that sort -f also converts small caps in capital. it was just an idea. but thanks for the nawk.

This is only for sorting considerations. That is "mike" and "Mike" would be appear together in the sorted list rather than "mike" appearing with lower case letters and "Mike" appearing with upper case letters.

Would you pls explain these 2 lines:

typeset -u -L1 f=$UN
print ${f}${UN#@([a-z])}

Thanks in advance.

Regards,
Tayyab

typeset -u -L1 f=$UN

This creates a variable called "f" that forces all characters to upper case (-u) and can only have a single character (-L1) and assigns it the values of $UN, which is truncated to 1 character and changed to upper case.

print ${f}${UN#@([a-z])}

Prints the new 1 character, upper case letter, and applies a KSH expression to $UN and removes the first (#@()) lower case ([a-z]) character leaving all of the rest in tact. $UN is left unchanged in the variable itself but as it is expanded in the print command the expression is applied and the first lower case letter is left off.

Thanks a lot for your explanation.

Hi

Don't want to beat a dead horse but following could be an alternative and i believe much simpler solution

while read name
do
name=`echo $name|awk -F":" '{print $1}'`
first_letter_small=`echo $name|cut -b 1`
first_letter_caps=`echo $first_letter_small | tr [a-z] [A-Z]`
remaining_word=${name#$first_letter_small}
new_name=$first_letter_caps$remaining_word
echo $new_name
done < /etc/passwd

Vikas.

How is this:

while read name
do
name=`echo $name|awk -F":" '{print $1}'`
first_letter_small=`echo $name|cut -b 1`
first_letter_caps=`echo $first_letter_small | tr [a-z] [A-Z]`
remaining_word=${name#$first_letter_small}
new_name=$first_letter_caps$remaining_word
echo $new_name
done < /etc/passwd

simpler than this? :smiley:

nawk -F: '{ print toupper(substr ($1,1,1)) substr ($1,2) }' /etc/passwd 

Well

Not everybody is comfortable with awk or nawk..Anyways, just wanted to give an alternative (may be not simpler for awk/nawk gurus) way to accomplish the task.

Did not hurt anyone, did it?

there's not better time than now to get better.........

Here's an arcane way of doing it with vi and process substitution (if you want to capitalise the usernames of logged on users, for example)....

vi +'1,$s/^./\U&/gp|q!' <(who | awk '{print $1}') | egrep -v 'changed|regular'

Edit: you can use ex too... for example on the /etc/passwd file itself, to capitalise the first character of each line....

( echo '1,$s/^./\U&/g'; echo '1,$p'; echo 'q!' ) | ex -s /etc/passwd

Cheers
ZB

newlisp -e '(silent)
(while(setq s(read-line))
  (println(title-case(first(parse s)))))' <file