Artificial intelligent assistant

Changing the first letter after ] to uppercase I have a CSV file in which I have thousands of lines like this: bla bla blab [FR] john is bla bla bla [US] blue house in Chicago... [ES] accessing the safe... bla bla See the elements between `[ ]`? These elements are always followed by a space and the start of a new phrase. I want to convert the first letter found after the space to uppercase, making the file like bla bla blab [FR] John is bla bla bla [US] Blue house in Chicago... [ES] Accessing the safe... bla bla How do I do that from terminal, using, sed, awk or whatever? Please explain the solution, I want to understand and learn. Thanks.

If on a GNU system, you can use `sed`:


sed 's/] ./\U&/g'

**s** tream **ed** itor ' **s** ubstitute/ _replace-what_ / _replace-with_ / **g** lobally'
Here " _replace-what_ " is a literal `]` followed by a single space ` ` then a single character (`.` matches a single character except `\
`ewline but would match a `\
`ewline character if it was ever found in the pattern space. In `perl`, it doesn't unless the `s` flag is added to the regex.)

" _replace-what_ " is `\U&`, in sed `&` is back-reference to "replace-what" part (`\U` stands for `\Upper-case`), so `\U&` will replace matched part to Upper-case.

* * *

If your `sed` is not GNU `sed`, you could do the same with `perl` with:


perl -Mopen=locale -pe 's/] ./\U$&/g' < infile

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 49178c0f4551c37abd81a33808a4d4cc