A string of uppercase characters in shell scripts

I have a meaning like: <Strong> James, Adam, John I'm trying to do it James, Adam, John (the first character of each name should be upper)

According to kev (below),

$ echo 'james, adam, john' | sed 's / \ </ \ u & / g' James, Adam, John (it does not work on all systems)

I can not do the same in another system. I use .ksh, but I don’t know, because of its ksh or other system. Can anyone help?

thanks

+1
source share
3 answers

You can use sed :

 $ echo 'james,adam,john' | sed 's/\<./\u&/g' James,Adam,John 
  • pattern \<. will match the first char of each word
  • use \u& to make it uppercase.
+4
source

Using bash:

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

Output:

 James Adam John 
+2
source

There are endless possibilities, but take a look at tr and shell line replacement (if your shell supports it). Then there are GNU sed , awk, perl and many other languages ​​...

+1
source

Source: https://habr.com/ru/post/1432552/


All Articles