Search code examples
textsedstreameditorgnu

Using Sed to capitalize the first letter of the first word in the sentences (each sentence starts with a double hyphen, -- )


I would like to try to use the Sed command to capitalize the first letter of the first word in the sentences, in a text where all the sentences begin with a double hyphen and one space.

For example, I would like to transform this text:

Pluto Is A Dwarf Planet -- Chemical Elements Are Cool -- Astronomical Objects Live In Space -- The Solar System Is Our Home -- I Want To Live On Another Planet Next To My Wife.

Into this one:

Pluto is a dwarf planet -- Chemical elements are cool -- Astronomical objects live in space -- The solar system is our home -- I want to live on another planet next to my wife.

(There is no line break, it's a whole block of text).

Thank you in advance for your help!

I tried to read the documentation, but it is very vast and I haven't found it yet...


Solution

  • This might work for you (GNU sed):

    sed 's/.*/\L&/;s/^.\|-- ./\U&/g' file
    

    Prepare the way by making every character lowercase.

    Then translate the first character or the first character following -- into its uppercase equivalent.