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

后端 未结 6 1639
无人及你
无人及你 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:34

    Use sed:

    sed  's/^\(.\)/\U\1/' yourfile > convertedfile
    

    Little explanation:

    • the ^ represents the start of a line.
    • . matches any character
    • \U converts to uppercase
    • \( ... \) specifies a section to be referenced later (as \1 in this case); parentheses are to be escaped here.

    Do not try to redirect the output to the same file in one command (i.e. > yourfile) as you will lose your data. If you want to replace in the same file then check out joelparkerhenderson's answer.

提交回复
热议问题