I’m looking for a way to capitalise the first character after a given string in multiple text files all in the same directory. I’m thinking sed is the tool to use for this.

For example, the text files all contain the string ‘name=‘ and I want to capitalise the letter that follows. Sometimes there is more than one instance of ‘name=‘ in the one file. The character following is always a letter and sometimes it already is uppercase. There are also other instances of ‘=‘ that don’t have ‘name’ behind them.

Can anyone point me in the right direction here? I’m more than happy to learn how myself I’m just not sure where to look.


  • 3
    why dont you give a sample input and expected output
    – Kamaraj
    Feb 28, 2018 at 7:35
  • you'll need GNU sed (gnu.org/software/sed/manual/sed.html#The-_0022s_0022-Command) or use awk/perl..
    – Sundeep
    Feb 28, 2018 at 7:38
  • 1
    The solution will depend on the format of the data. If the format is XML or JSON or some other structured format, a solution using the appropriate parser would be required.
    – Kusalananda
    Feb 28, 2018 at 7:49

1 Answer 1


With GNU sed, you can do it simply:

sed '/name=[a-z]/s/name=\(.\)/name=\U\1/g'


  1. \(.\) defines a regex collection group of a single character.

  2. \U tells sed to convert something to upper-case.

  3. \1 refers back to the first collection group, ie. the character you want capitalized.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.