How can I capitalize the first letter of each word?

前端 未结 20 2320
暖寄归人
暖寄归人 2021-01-14 12:31

I need a script in any language to capitalize the first letter of every word in a file.

Thanks for all the answers.

Stackoverflow rocks!

20条回答
  •  时光说笑
    2021-01-14 12:33

    From the shell, using ruby, this works assuming your input file is called FILENAME, and it should preserve all existing file formatting - it doesn't collapse the spacing as some other solutions might:

    cat FILENAME | ruby -n -e 'puts $_.gsub(/^[a-z]|\s+[a-z]/) { |a| a.upcase }'
    

提交回复
热议问题