Changing the case of a string with awk

前端 未结 4 1541
死守一世寂寞
死守一世寂寞 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:26

    You have to add another \ character before \B

     echo 'ABCD EFGH IJKL MNOP' | awk '{for (i=1;i <= NF;i++)
     {sub("\\B[A-Za-z]+",substr(tolower($i),2),$i)} print}'
    

    With just \B awk gave me this warning:

    awk: cmd. line:1: warning: escape sequence \B' treated as plainB'

提交回复
热议问题