Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lowercase to Uppercase of character in Shell Scripting [duplicate]

Possible Duplicate:
Character Lowercase to Uppercase in Shell Scripting

I have value as: james,adam,john I am trying to make it James,Adam,John (First character of each name should be Uppercase).

echo 'james,adam,john' | sed 's/\<./\u&/g'

is not working in all the systems. In one system its showing ok..but not ok in another system...

A="james adam john"
B=( $A )
echo "${B[@]^}"

its throwing some syntax error...So, i am doing it through a long query sing while loop, which is too lengthy. Is there any shortcut way to do this?

like image 950
par181 Avatar asked Dec 12 '22 22:12

par181


2 Answers

There are many ways to define "beginning of a name". This method chooses any letter after a word boundary and transforms it to upper case. As a side effect, this will also work with names such as "Sue Ellen", or "Billy-Bob".

echo "james,adam,john" | perl -pe 's/(\b\pL)/\U$1/g'
like image 76
TLP Avatar answered May 10 '23 14:05

TLP


With Perl:

echo "james,adam,john" | \
  perl -ne 'print  join(",", map{ ucfirst } split(/,/))'
like image 43
perreal Avatar answered May 10 '23 16:05

perreal