Improve compatibility with non-GNU versions of Bash.

- Because GNU sed uses -r and POSIX sed uses -E to specify extended
    regexp syntax, the script was dying with sed -r on OSX. Work around
    the issue by rephrasing the regex not to use extended syntax.
- Bash v4 introduces the ^^ capitalization operation, but it isn't
    available on Bash pre-4. Replace with tr.
- Fix a small spelling error.