Changing the first letter of every line in a file to uppercase

后端 未结 6 1641
无人及你
无人及你 2021-01-02 11:04

I need to change the first letter of every line in a file to uppercase, e.g.

the bear ate the fish.
the river was too fast.

Would become:

6条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-02 11:13

    There's a few sed answers with s/^\(.\)/\U\1/. GNU sed also has a \u directive that changes only the next letter to uppercase, so

    sed 's/./\u&/'
    

    Although if the first character on a line is a space, you won't see an uppercase letter, so

    sed 's/[[:alpha:]]/\u&/'
    

提交回复
热议问题