Changing the case of a string with awk

前端 未结 4 1540
死守一世寂寞
死守一世寂寞 2021-02-20 15:55

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

4条回答
  •  礼貌的吻别
    2021-02-20 16:06

    My solution will be to get the first part of the sub with a first substr insted of your regex :

    echo 'ABCD EFGH IJKL MNOP' | awk '{for (i=1 ; i <= NF ; i++) {sub(substr($i,2),tolower(substr($i,2)),$i)} print }'
    Abcd Efgh Ijkl Mnop
    

提交回复
热议问题