How to use REGEX to capitalise the first letter of each word in a sentence?

Example using sed command.

~$ echo "foo bar" | sed  's/^\(.\)/\U\1/'

Where:

  • 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).