I\'m an awk newbie, so please bear with me.
The goal is to change the case of a string such that the first letter of every word is uppercase and the remaining letters ar
When matching regex using the sub()
function or others (like gsub()
etc), it's best used in the following form:
sub(/regex/, replacement, target)
This is different from what you have:
sub("regex", replacement, target)
So your command becomes:
awk '{ for (i=1;i<=NF;i++) sub(/\B\w+/, substr(tolower($i),2), $i) }1'
Results:
Abcd Efgh Ijkl Mnop
This article on String Functions maybe worth a read. HTH.
I should say that there are easier ways to accomplish what you want, for example using GNU sed
:
sed -r 's/\B\w+/\L&/g'